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

"Not a date-time" error on search when using datetimes with timezones #904

Open
tbarsballe opened this issue Mar 30, 2023 · 0 comments
Open
Labels

Comments

@tbarsballe
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants