-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I am using a Pydantic model describing my dataset and then creating a Record instance from that model. The Record model declares that the types are all meant to be datetime.date and that's what my model uses. This works in python 3.12 but now in python 3.13 I get:
@field_validator("publication_date", mode='before')
@classmethod
def parse_date(cls, value) -> date:
"""
Define several acceptable date-string formats to parse.
"""
format_strings=["%m/%d/%Y", "%m/%d/%y", "%Y-%m-%d"]
# attempt each format to attempt parsing dates
for format in format_strings:
try:
> return datetime.strptime(value, format).date()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E TypeError: strptime() argument 1 must be str, not datetime.dateI imagine that in python 3.12 strptime was stringifying the date and then it was working but now it's more correct.
Would it be possible for your validator to be updated to add
if isinstance(value, datetime.date):
return valuesince it seems strange that both models should use date but I have to force back to string to construct the Record.
Metadata
Metadata
Assignees
Labels
No labels