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

Add POST support to WFS GetFeature (Issue #439) #706

Merged
merged 27 commits into from
Nov 26, 2020

Conversation

f-PLT
Copy link
Contributor

@f-PLT f-PLT commented Sep 23, 2020

This PR would take care of issues #439 and possibly #683

This is my first contribution to OWSLib and I'm new to the WFS standard, so I expect there might be a few things to change, either towards the standards or to integrate it better with existing code.

I added the ability to use an existing xml filter as is, like suggested in #439, but I think it might be redundant. Either way, it's self contained and only 2 lines of code, so it's easy to remove if need be.

I can already say I'm not sure about how I handled Stored Queries.

@huard
Copy link
Contributor

huard commented Sep 28, 2020

I'm not familiar with this part of the code, but the use case for us to send requests to GeoServer that exceed the size of GET requests. For example, we're sometime making queries for properties for thousands of individual features, and the list of features does not fit in GET requests. So we'd be really grateful if this could be reviewed.

@cehbrecht cehbrecht added the wfs label Sep 28, 2020
@cehbrecht cehbrecht self-requested a review September 30, 2020 09:00
Copy link
Contributor

@cehbrecht cehbrecht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks fine .... but I have not tested.

@cehbrecht
Copy link
Contributor

test failures not related to this PR.

@KorkXx
Copy link

KorkXx commented Nov 4, 2020

Just added #711 which this PR should solve

if not typename and filter:
return base_url, filter

request = self.create_post_request()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not understand why using a create_post_request function instead of directly inserting the version-dependent Postrequest object creation. Is this function intended to be used anywhere else ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, my aim here was to make the post request creation more testable. It being separated makes it testable by itself.

I chose to make a factory with create_post_request(), so getPOSTGetFeatureRequest() can be used for wfs1.1.0 and 2.0.0 without needing another function that does almost the same thing but not quite, which also seems to be what getGetGetFeatureRequest() is aiming to become.

So this way, getFeature(), whether it's with 1.1.0 or 2.0.0, calls the same function, which checks the WFS version, and builds the appropriate request format. It will also make it easier (I hope) to integrate the next WFS version by simply extending the postrequest.py module so it can format post requests for that new version. All without needing to change getPOSTGetFeatureRequest() or creating a new function.

On the plus side, postrequest.py can also be used by itself to build a request and use it with resquests.post(), which could be useful in identifying if an error is caused by the request itself or if the problem is somewhere else in OWSLib.

@cehbrecht
Copy link
Contributor

@KorkXx @f-PLT @tomkralidis If the review is ok, can we merge it?

@tomkralidis
Copy link
Member

+1

@f-PLT
Copy link
Contributor Author

f-PLT commented Nov 23, 2020

We have an issue with a usecase for one of our partners.

If it can't be handled server-side, we'll probably have a small change to add so it's possible to handle an https redirection, which doesn't seem to work with Post requests.

Right now, considering a simple flag to prevent the GetCapabilities url retrieval when needed, and force the use of the provided WebFeatureService url as is. (for reference : https://github.com/f-PLT/OWSLib/blob/wfs-getfeature-post/owslib/feature/__init__.py#L312-L320)

@f-PLT
Copy link
Contributor Author

f-PLT commented Nov 24, 2020

Alright, it's definitely a server-side problem so we'll fix it server-side. If there are no other objections after the testing has been done , it should be ok to merge.

As for the problem, here's a summary as it's bound to happen to other people.

Post requests are not redirected. Ever, and should never be. It's in the HTTP standards. (Learn something everyday!)

Therefore if the the Url listed in the GetCapabilities for post getFeature() is http://..., but the server is behind, say, an nginx proxy that redirects http => httpS, the post request will not work and return a very helpful error :

owslib.util.ServiceException: Could not determine geoserver request from http request org.geoserver...

The server needs to be configured to give the proper url. In the case of Geoserver, it should be the Proxy Base Url.

This doesn't happen with Get requests, because a Get can be redirected without any problem.

Hope this little bit of information can help someone someday, and if I'm wrong in any way, please feel free to correct me!

@cehbrecht
Copy link
Contributor

Alright, it's definitely a server-side problem so we'll fix it server-side. If there are no other objections after the testing has been done , it should be ok to merge.

@f-PLT ok :) Give me a sign ... I can do the merge ...

For WFS 1.1.0
With Post method now being available, having propertyname='*' as a
default value  causes problems for the post request. Default value
is now None, just like for 2.0.0.

Since I don't know if there are cases where this default was necessary,
added a condition when `method=get` to set propertynames to '*' is
it's not assigned a value.
@f-PLT
Copy link
Contributor Author

f-PLT commented Nov 24, 2020

Our tests have gone well!

Found and corrected a small unintended side effect while we were at it. If these last three commits pass muster, then it's good to go. If we end up finding more bugs, I'll open a new PR.

@f-PLT f-PLT requested a review from cehbrecht November 25, 2020 19:08
@cehbrecht
Copy link
Contributor

failing tests are not related to this PR ... they already fail on current master.

@cehbrecht cehbrecht merged commit 568c4f7 into geopython:master Nov 26, 2020
@cehbrecht
Copy link
Contributor

@f-PLT merged. Thanks 👍

@huard huard mentioned this pull request Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants