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
{{ message }}
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
Postgres backend Record is a Mapping but some Mapping methods are deprecated #407
Meanwhile, postgres backend's Record object inherits from collections.abc.Mapping and is therefore required to fulfill the Mapping interface, which includes keys() and values() which are now deprecated.
Sqlalchemy provides a mapping() method on Result which will cause it to return RowMapping objects rather than Row objects, and those look like Mappings.
I encountered this issue working with fastapi and pydantic. Returning Records as pydantic models worked in the past, but now produces a deprecation warning (and i guess will eventually stop working) since pydantic's builtin validator treats the Record as a Mapping and attempts to call dict(record)
FYI I did some more testing, and I think that changing the parent class of Record from collections.abc.Mapping to collections.abc.Sequence does not solve the particular issue with pydantic attempting to dict the Record.
I think we can ignore pydantic within the context of this issue. The basic
issue is that an abc.Mapping should implement keys and values, but calling
keys or values on Record is deprecated.
@ugtar Yes in that case you are right, Mapping should implement keys() and values(), items(), etc but it doesn't.
I don't see the point in keeping that a Mapping anymore.
Since #299 upgraded to sqlalchemy 1.4, the postgres backend's Record object now mimics the behavior of sqlalchemy's Row which is meant to behave similarly to a NamedTuple (and inherits from collections.abc.Sequence) https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#change-4710-core
Meanwhile, postgres backend's Record object inherits from collections.abc.Mapping and is therefore required to fulfill the Mapping interface, which includes keys() and values() which are now deprecated.
Sqlalchemy provides a
mapping()method on Result which will cause it to return RowMapping objects rather than Row objects, and those look like Mappings.I encountered this issue working with fastapi and pydantic. Returning Records as pydantic models worked in the past, but now produces a deprecation warning (and i guess will eventually stop working) since pydantic's builtin validator treats the Record as a Mapping and attempts to call
dict(record)