You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When datetime is used within the context of freeze_time the check on the field_value is type(field_type) will compare FakeDatetime is datetime and resolve to False. Where-as outside of the freeze_time context datetime is handled correctly.
Code snippet that reproduces the issue
fromdataclassesimportdataclass, fieldfromdatetimeimportdatetimefromdataclasses_jsonimportconfig, dataclass_jsonfromfreezegunimportfreeze_timeimportdateutil.parserdefiso8601_datetime(s: str):
returndateutil.parser.parse(s).replace(tzinfo=None)
DATETIME_CONFIG=config(decoder=iso8601_datetime)
@dataclass_json@dataclassclassMessage:
dt: datetime=field(metadata=DATETIME_CONFIG)
message=Message.from_dict({"dt": datetime(2023, 1, 24, 11, 36, 21)})
print(message)
withfreeze_time("2023-01-09 21:57:32"):
dt=datetime(2023, 1, 24, 11, 36, 21)
message=Message.from_dict({"dt": dt}) # Results in `Parser must be a string or character stream, not FakeDatetime`print(message)
Describe the results you expected
Ideally FakeDatetime should be treated the same as a datetime and not fallback to passing the FakeDatetime to the decoder as this behaviour doesn't occur with the regular datetime.
Python version you are using
Python 3.9.9
Environment description
freezegun==1.4.0
python-dateutil==2.8.2
The text was updated successfully, but these errors were encountered:
Description
When
datetime
is used within the context offreeze_time
the check on thefield_value is type(field_type)
will compareFakeDatetime is datetime
and resolve toFalse
. Where-as outside of the freeze_time contextdatetime
is handled correctly.Code snippet that reproduces the issue
Describe the results you expected
Ideally FakeDatetime should be treated the same as a
datetime
and not fallback to passing the FakeDatetime to thedecoder
as this behaviour doesn't occur with the regulardatetime
.Python version you are using
Python 3.9.9
Environment description
freezegun==1.4.0
python-dateutil==2.8.2
The text was updated successfully, but these errors were encountered: