flagsmith icon indicating copy to clipboard operation
flagsmith copied to clipboard

`util.pydantic.exclude_model_fields` fails when inside `freezegun.freeze_time`

Open khvn26 opened this issue 1 year ago • 1 comments
trafficstars

The code here causes tests to fail with the following error:

pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for [class 'datetime.datetime'](https://app.slack.com/client/TTKSY58MC/class%20'datetime.datetime'). Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

Related discussion: https://github.com/pydantic/pydantic/discussions/9343

khvn26 avatar May 01 '24 16:05 khvn26

Currently, the way to fix this is to add the following to api/conftest.py:

def pytest_sessionstart(session):
    from environments.sdk.schemas import SDKEnvironmentDocumentModel

A less hacky way to avoid the error would be something like

import freezegun

freezegun.configure(extend_ignore_list=["pydantic"])

but it will need a bit more trial and error to determine the exact module name to ignore.

khvn26 avatar May 01 '24 19:05 khvn26

Fixed by workaround applied in https://github.com/Flagsmith/flagsmith/pull/3876. We should in future be able to remove the workaround if/when freezegun resolves the issue, but the workaround is sufficient for now.

matthewelwell avatar May 22 '24 12:05 matthewelwell