New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Postgres backend Record is a Mapping but some Mapping methods are deprecated #407
Comments
the workaround I suppose is to do something like results = await database.fetch_all(query)
return [r._mapping() for r in results] instead of simply returning results as before. Still, I hope that having a correct type for Record will make that unnecessary. |
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 |
Sorry I'm a little confused now, I don't know much about Pedantic. [r._mapping for r in results] But calling |
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.
…--
Uri
Please consider the environment before printing this message.
http://wwf.panda.org/savepaper/
On Tue, Oct 12, 2021, 4:22 AM Amin Alaee ***@***.***> wrote:
Sorry I'm a little confused now, I don't know much about Pedantic.
Do you mean that this works in Pydantic?
[r._mapping for r in results]
But calling dict(record) produces DeprecationWarning?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#407 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAXQTKXMT5BCT6GZHNKEZ3UGPV6FANCNFSM5FYZZ6HA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
@ugtar Yes in that case you are right, |
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)
The text was updated successfully, but these errors were encountered: