Skip to content

Conversation

@gadomski
Copy link
Member

@gadomski gadomski commented Oct 21, 2022

Related Issue(s):

Description:

The stringified intersects dictionary was being double-stringified. This fix uses urllib.parse.quote_plus to urlencode the intersects string for GET requests.

Includes:

  • Request parameter assertions using pytest-httpserver
  • Denser intersects stringification to increase chance of GET request being short enough

This fix proved hard to test using the existing procedures, because stac-fastapi does not support intersects for GET requests: stac-utils/stac-fastapi#468.

PR Checklist:

  • Code is formatted
  • Tests pass
  • Changes are added to the CHANGELOG

@gadomski gadomski requested a review from philvarner October 21, 2022 20:37
@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2022

Codecov Report

Base: 85.50% // Head: 85.87% // Increases project coverage by +0.37% 🎉

Coverage data is based on head (5a67ddf) compared to base (23b570d).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #337      +/-   ##
==========================================
+ Coverage   85.50%   85.87%   +0.37%     
==========================================
  Files          11       11              
  Lines         800      800              
==========================================
+ Hits          684      687       +3     
+ Misses        116      113       -3     
Impacted Files Coverage Δ
pystac_client/item_search.py 92.97% <100.00%> (ø)
pystac_client/stac_api_io.py 89.18% <100.00%> (+2.70%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@gadomski gadomski mentioned this pull request Oct 21, 2022
3 tasks
@gadomski gadomski force-pushed the issues/335-double-encoding-get branch from f61b7c9 to b739a1d Compare October 21, 2022 21:08
@gadomski gadomski marked this pull request as draft November 28, 2022 18:20
@gadomski
Copy link
Member Author

I'm converting this to draft because I'd like to test it on a real-world server implementation first. For #362, I couldn't url encode the parameter when testing against the Planetary Computer. I'd like to know whether that's a server bug, which will determine whether we url encode the intersects parameter in this PR.

@gadomski gadomski added this to the 0.5.2 milestone Dec 13, 2022
@gadomski
Copy link
Member Author

To keep this moving, and in liu of a production system to run a real-world test against, I tested this against stac-utils/stac-fastapi@97b0911 with the following patch:

diff --git a/stac_fastapi/pgstac/stac_fastapi/pgstac/core.py b/stac_fastapi/pgstac/stac_fastapi/pgstac/core.py
index 9b194f7..68d7620 100644
--- a/stac_fastapi/pgstac/stac_fastapi/pgstac/core.py
+++ b/stac_fastapi/pgstac/stac_fastapi/pgstac/core.py
@@ -358,6 +358,9 @@ class CoreCrudClient(AsyncBaseCoreClient):
         """
         request = kwargs["request"]
         query_params = str(request.query_params)
+        import json
+        import urllib.parse
+        print(json.loads(urllib.parse.unquote_plus(kwargs["intersects"][0])))
 
         # Kludgy fix because using factory does not allow alias for filter-lang
         if filter_lang is None:

I then ran:

cd stac-fastapi && docker-compose up &
cd ../pystac-client && stac-client search --method GET http://localhost:8082 --intersects '{"type":"Point","coordinates":[-105.1019,40.1672]}'

Relevant output:

stac-fastapi-pgstac                   | {'type': 'Point', 'coordinates': [-105.1019, 40.1672]}
stac-fastapi-pgstac                   | INFO:     172.19.0.1:56374 - "GET /search?limit=100&intersects=%257B%2522type%2522%253A%2522Point%2522%252C%2522coordinates%2522%253A%255B-105.1019%252C40.1672%255D%257D HTTP/1.1" 200 OK

I'm going to call that good for now, and mark this PR as ready-to-review.

@gadomski gadomski marked this pull request as ready for review December 13, 2022 16:09
@gadomski gadomski force-pushed the issues/335-double-encoding-get branch from f3895f6 to 27c7df3 Compare December 13, 2022 16:14
@philvarner
Copy link
Collaborator

I tried it against three instances:

# url = "https://earth-search.aws.element84.com/v1"
# collection="sentinel-2-l2a"

# url = "https://planetarycomputer.microsoft.com/api/stac/v1"
# collection="sentinel-2-l2a"

url = "https://tamn.snapplanet.io"
collection="S2"

with 0.5.1, I got:

  • Earth Search: 500 internal error (not clear what the problem is)
  • PC: never stops (so likely the next link is just on repeat)
  • Snapplanet: works

with this change, I got:

  • Earth Search: 400 {"code":"BadRequest","description":"Invalid GeoJSON geometry"}
  • PC: never stops
  • Snapplanet: error

@gadomski
Copy link
Member Author

with this change, I got:
Earth Search: 400 {"code":"BadRequest","description":"Invalid GeoJSON geometry"}
Snapplanet: error

This makes me think that those servers aren't unquoting the param before parsing it as JSON. Per #362 (comment) this is technically a bug, but since

  1. we don't have control over those servers
  2. they're commonly used
  3. there's probably other servers that don't unquote the param

this makes me think we shouldn't url-quote the param here or in #362. @philvarner thoughts?

@gadomski gadomski removed this from the 0.5.2 milestone Dec 15, 2022
@gadomski gadomski self-assigned this Dec 30, 2022
@gadomski gadomski marked this pull request as draft January 19, 2023 21:51
@gadomski gadomski added the question Further information is requested label Jan 20, 2023
@gadomski gadomski mentioned this pull request Apr 3, 2023
3 tasks
@gadomski
Copy link
Member Author

gadomski commented Apr 3, 2023

Closing as OBE (#362 (comment)).

@gadomski gadomski closed this Apr 3, 2023
@gadomski gadomski deleted the issues/335-double-encoding-get branch April 3, 2023 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double encoding of intersects request ?

4 participants