"Not a date-time" error on search when using datetimes with timezones
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start at data_filter.date_range_filter and follow how datetime values are serialized into the search request. Reproduce the failure with the timezone-aware datetime in the provided sample; done means the client either sends an accepted date-time or reports a clear validation error before submission.
Written by the indexing model from the issue text.
Description
Expected behavior
The search client should accept any valid datetime.
Actual behavior (describe the problem)
When submitting a search request that includes a datetime filter, if the datetime provided includes a tzinfo, the request will fail with the following error:
planet.exceptions.BadQuery: {"field": {"filter.config.0.config.gte": [{"message": "'2022-04-01T00:00:00+00:00Z' is not a 'date-time'"}]
I'm mostly concerned about how obtuse the actual error is - 2022-04-01T00:00:00+00:00Z is definitively a date-time, the added tzinfo just changes the formatting so that the API does not accept it as such. The client should either reject such datetimes before submitting the search, with a clearer error; or format them appropriately, such that the search is valid.
Related Issues
#143 (although that one looks to be from V1)
Workaround
Don't include a tzinfo in datetimes
Minimum, Complete, Viable Code Sample
Configure your API key before running
from datetime import datetime
import pytz
import asyncio
from planet import data_filter, Session
item_type = "PSScene"
product_bundle = "visual"
# Add UTC timezone to TOIs:
toi_start = datetime.fromisoformat("2022-04-01")
toi_end = datetime.fromisoformat("2022-04-28")
#Comment these two lines out and it'll work fine
toi_start = toi_start.replace(tzinfo=pytz.UTC)
toi_end = toi_end.replace(tzinfo=pytz.UTC)
async def main():
async with Session() as sess:
search_filter = data_filter.date_range_filter("acquired", gte=toi_start, lte=toi_end)
ids = [i["id"] async for i in sess.client("data").search([item_type], search_filter, limit=10)]
print(f"""{len(ids)} scenes were found.""")
return ids
asyncio.run(main())
Environment Information
- Operation System Information: MacOS 13.2.1
- Python version: 3.9
- Planet package version: 2.0rc2
Installation Method
- pip
- Dominant language
- Python
- Stars
- 299
- Forks
- 100
- Avg merge
- 7d 8h
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from planetlabs/planet-client-python
-
better-testing
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
planetlabs/planet-client-python#1110 ·
-
proposal
Difficulty 3/5 1-2 days Newbie friendliness 65/100
planetlabs/planet-client-python#1221 ·
-
proposal
Difficulty 3/5 1-2 days Newbie friendliness 57/100
planetlabs/planet-client-python#1214 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 48/100
planetlabs/planet-client-python#1197 · 1 comment · 1 reaction ·
-
Quota API Openai-claude
planetlabs/planet-client-python#1191 · 1 comment · 1 assignee ·
All issues in planetlabs/planet-client-python
Similar issues
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100