pycsw icon indicating copy to clipboard operation
pycsw copied to clipboard

Bug: CSW generates wrong DB queries while nesting logical operators (AND, OR)

Open asafMasa opened this issue 3 years ago • 0 comments

Description

While using a nested query we experienced an issue which we think is a bug with the generated query in the CSW.

The Query we used: <csw:Constraint version="1.1.0"> <Filter xmlns="http://www.opengis.net/ogc"> <Or> <And> <PropertyIsLike wildCard="%" singleChar="_" escapeChar="\\"> <PropertyName>id</PropertyName> <Literal>e6c331ca-f077-452c-9811-25fc9d99acd2</Literal> </PropertyIsLike> <PropertyIsLike wildCard="%" singleChar="_" escapeChar="\\"> <PropertyName>version</PropertyName> <Literal>1</Literal> </PropertyIsLike> </And> <And> <PropertyIsLike wildCard="%" singleChar="_" escapeChar="\\"> <PropertyName>externalId</PropertyName> <Literal>test</Literal> </PropertyIsLike> <PropertyIsLike wildCard="%" singleChar="_" escapeChar="\\"> <PropertyName>externalId</PropertyName> <Literal>test</Literal> </PropertyIsLike> </And> </Or> </Filter> </csw:Constraint>

Pycsw Log: [DEBUG] file=/home/pycsw/pycsw/ogc/csw/csw2.py line=815 module=csw2 function=getrecords Querying repository with constraint: { 'type': 'filter', 'where': '(identifier like :pvalue0 and version like :pvalue1) or (identifier like :pvalue0 and version like :pvalue1 and externalId like :pvalue2 and externalId like :pvalue3)', 'values': ['e6c331ca-f077-452c-9811-25fc9d99acd2', '1', 'test', 'test'], 'dict': {'ogc:Filter': {'ogc:Or': {'ogc:And': [{'ogc:PropertyIsLike': [{'@wildCard': '%', '@singleChar': '', '@escapeChar': '\\', '@xmlns': {'': 'http://www.opengis.net/ogc', 'csw': 'http://www.opengis.net/cat/csw/2.0.2', 'mc': 'http://schema.test.com/test'}, 'ogc:PropertyName': 'id', 'ogc:Literal': 'e6c331ca-f077-452c-9811-25fc9d99acd2'}, {'@wildCard': '%', '@singleChar': '', '@escapeChar': '\\', 'ogc:PropertyName': 'version', 'ogc:Literal': '1'}]}, {'ogc:PropertyIsLike': [{'@wildCard': '%', '@singleChar': '', '@escapeChar': '\\', 'ogc:PropertyName': 'externalId', 'ogc:Literal': 'test'}, {'@wildCard': '%', '@singleChar': '_', '@escapeChar': '\\', 'ogc:PropertyName': 'externalId', 'ogc:Literal': 'test'}]}]}}}}, sortby: None, typenames: ['mc:MCRecord'], maxrecords: 10, startposition: 1

It seems from the log that the second "And" condition has a bug as the first "And" condition parameters where inserted into it (as was marked with BOLD in the log)

Environment

  • operating system:
  • Linux-4.18.0-305.45.1.el8_4.x86_64
  • Python version:
  • 3.8.13
  • pycsw version:
  • 2.7-dev
  • source/distribution
    • [X] git clone
    • [ ] DebianGIS/UbuntuGIS
    • [ ] PyPI
    • [ ] zip/tar.gz
    • [ ] other (please specify):
  • web server
    • [X] Apache/mod_wsgi
    • [ ] CGI
    • [ ] other (please specify):

Steps to Reproduce

Use a query like the one provided.

Additional Information

asafMasa avatar Sep 21 '22 10:09 asafMasa