-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bug] Stop coercion of strings into datetime objects (#255)
## Problem Sometimes when strings are stored as metadata values, later fetching or querying causes those values to be coerced into datetime objects by the client before they are presented to the caller. This is a default behavior in the generated openapi client that is a result of the python `datetime` constructor working quite hard to turn things into dates. We've seen scenarios where this was not desired, so for now we will disable this conversion process to have consistent handling of all strings. People who desire date objects can easily implement the conversion themselves. ## Solution - Update openapi templates to comment out and remove logic related to converting strings into date and datetime objects. - Regenerate client with new templates - Add unit test verifying the type coercion does not take place. ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) ## Test Plan `poetry run pytest tests/unit/data`
- Loading branch information
Showing
2 changed files
with
60 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from pinecone import Vector, Config | ||
from datetime import datetime | ||
|
||
class TestDatetimeConversion: | ||
def test_datetimes_not_coerced(self): | ||
vec = Vector(id='1', values=[0.1, 0.2, 0.3], metadata={'created_at': '7th of January, 2023'}, _check_type=True, _configuration=Config()) | ||
assert vec.metadata['created_at'] == '7th of January, 2023' | ||
assert vec.metadata['created_at'].__class__ == str | ||
|
||
def test_dates_not_coerced(self): | ||
vec = Vector(id='1', values=[0.1, 0.2, 0.3], metadata={'created_at': '8/12/2024'}, _check_type=True, _configuration=Config()) | ||
assert vec.metadata['created_at'] == '8/12/2024' | ||
assert vec.metadata['created_at'].__class__ == str |