-
Notifications
You must be signed in to change notification settings - Fork 403
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
Support pickling Record-s #1000
base: master
Are you sure you want to change the base?
Conversation
@elprans Hi! Please could you kindly take a look at this PR? We've faced the same problem with difficulties of Records' pickling :( |
@@ -575,3 +570,11 @@ class MyRecordBad: | |||
'record_class is expected to be a subclass of asyncpg.Record', | |||
): | |||
await self.connect(record_class=MyRecordBad) | |||
|
|||
def test_record_pickle(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i suggest to write a test of pickling nested records
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postgres doesn't support returning nested records. asyncpg doesn't support nested records anywhere. I don't think it's a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nested composite types are returned as nested Record
instances, e.g:
import asyncio
import asyncpg
async def main():
conn = await asyncpg.connect()
await conn.execute('CREATE TYPE complex AS (r float, imag float)')
print(await conn.fetchrow("SELECT 1, '2', (3, 4)::complex"))
asyncio.run(main())
if (PyObject_Length(desc->mapping) != len) { | ||
return NULL; | ||
} | ||
PyObject *record = ApgRecord_New(&ApgRecord_Type, (PyObject *)desc, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would lose the original record subtype if one was used, so you need to pickle the class reference also.
OK, we seem to have different use cases and motivations with the maintainer here. Please feel free to close this PR since I am not planning any further work, unfortunately. If one doesn't leverage custom record classes and doesn't work with nested stuff, my fork is published and maintained as asyncpg-rkt on PyPi, together with many other improvements. |
I'm not sure how you reached this conclusion. I simply pointed out the inaccuracy of your statement regarding nested records which would need to be addressed for this to get merged. Other than that this is a valid and valuable improvement. |
Closes #451