Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent filter parameter in WFS 2.0.0 #804

Closed
denevers opened this issue Feb 19, 2022 · 0 comments
Closed

Inconsistent filter parameter in WFS 2.0.0 #804

denevers opened this issue Feb 19, 2022 · 0 comments

Comments

@denevers
Copy link

Greetings

Not sure if it's a bug or me misunderstanding.

In this small snippet (which works)

wfs20 = WebFeatureService(url='http://services.ga.gov.au/earthresource/wfs', version='2.0.0')
gold= """<fes:Filter  xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:erl="http://xmlns.earthresourceml.org/earthresourceml-lite/1.0">
      <fes:PropertyIsEqualTo>  
        <fes:ValueReference>erl:representativeCommodity_uri</fes:ValueReference>
        <fes:Literal>http://resource.geosciml.org/classifier/cgi/commodity-code/gold</fes:Literal>
      </fes:PropertyIsEqualTo>
    </fes:Filter>
"""
# Get some mineral occurrences
response = wfs20.getfeature(typename='erl:MineralOccurrenceView',maxfeatures=10,method="{http://www.opengis.net/wfs}Post",filter=etree.fromstring(gold))

filter parameter can either be a string on a etree Element, so filter=etree.fromstring(gold)or filter=gold should both work. If I pass the etree Element, it works fine, except it outputs a warning

(...)  feature\__init__.py:351: FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
  elif filter:

but If I use a string

# Get some mineral occurrences
response = wfs20.getfeature(typename='erl:MineralOccurrenceView',maxfeatures=10,method="{http://www.opengis.net/wfs}Post",filter=gold)

the WFS returns nothing because there are no filter, because this bit of code in postrequest.py (set_filter

        if isinstance(filter, str):
            f = etree.fromstring(filter)
            sub_elem = f.find(util.nspath("Filter", FES_NAMESPACE))
        else:
            sub_elem = filter

        self._query.append(sub_elem)

sub_elem returns Nothing (because it look only in f child ?)

so to make it work you must surround the filter with some dummy tag (and it then works for both string and Element)

gold= """<a><fes:Filter  xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:erl="http://xmlns.earthresourceml.org/earthresourceml-lite/1.0">
      <fes:PropertyIsEqualTo>  
        <fes:ValueReference>erl:representativeCommodity_uri</fes:ValueReference>
        <fes:Literal>http://resource.geosciml.org/classifier/cgi/commodity-code/gold</fes:Literal>
      </fes:PropertyIsEqualTo>
    </fes:Filter></a>
"""

Now, I assume the intent is not to build the filter with a `wfs:Query` around it because the code above specifically look for `Filter` and passing a etree Element just appends it as-is  And the parameter is called `filter`. Personnaly, adding a extra tag does not make sense.

So I guess there is a bug when the Filter is passed as a string (sans extra tag) and there is a waning message when an Element is passed.  




@huard huard closed this as completed in a70c46c Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant