baobabsoluciones / baobabsoluciones/cornflow
Timezone aware datetimes break queries
- Dominant language
- Python
- Stars
- 21
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
cornflow client api_for_id method doesn't work with a datetime argument with a timezone.
The problem is that when transformed to string, the timezone is shown a "+xx:00"
In the url, the "+" is interpreted as a space.
The "+" in the url should be transformed into "%2B"
Currently, api_for_id is processing the arguments that way:
```
if query_args is not None:
url = f"{url}?"
for key, value in query_args.items():
url = f"{url}{key}={value}&"
url = url[:-1]
```
**To Reproduce**
Steps to reproduce the behavior:
1. Choose any endpoint which use a datetime argument
2. create a timezone aware date with my_date = datetime.now(timezone.utc)
3. use cornflow client api_for_id with query_args = {"date": my_date}
4. The schema check for the date argument will fail.
**Expected behavior**
api_for_id and other api functions should checks if the arguments are dates and in that case replace the +.
Otherwise, the + should not be replaced because it might be intentional.
**Metadata (please complete the following information):**
- cornflow version 1.2.1
Contributor guide
Research direction
Locate the client api_for_id method and the other API functions that build query strings from query_args. Reproduce the issue with datetime.now(timezone.utc) and check the schema validation result; done means timezone-aware datetime arguments preserve the encoded plus sign without altering intentional plus signs in other values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100