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

Open
#904 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
api

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

bug

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from planetlabs/planet-client-python

All issues in planetlabs/planet-client-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.