Skip to content

Postgres and InMemory adapters should handle serialization the same way #36

@johncowie

Description

@johncowie

We've had a case where a datetime was slipping through the net as a valid JsonValue for the postgres storage adapter, but not for the in-memory storage adapter.

We think this is because we called .model_dump() on a model that had a datetime as one of the fields, but .model_dump() has a return type of dict[str, Any] so type-checking is unable to detect that a non-JsonValue is a value within that dict. It seems that the postgres library has support for serialising/deserialising datetimes for JSONB, so the postgres adapter doesn't complain, unlike the in-memory storage adapter which doesn't perform this serialisation automatically and thus does error.

I'd propose that datetime values should also be rejected by the postgres storage adapter, to ensure that the postgres and in-memory adapters behave the same way, thus preserving substitutability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions