Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support pickling Record-s #1000

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

Open
vmarkovtsev wants to merge 1 commit into MagicStack:master
base: master
Choose a base branch
Loading
from athenianco:upstream

Conversation

Copy link

@vmarkovtsev vmarkovtsev commented Feb 8, 2023

Closes #451

matthiasschaub reacted with thumbs up emoji
Copy link

@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):
Copy link

@frake23 frake23 Jul 17, 2023
edited
Loading

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

Copy link
Author

@vmarkovtsev vmarkovtsev Jul 17, 2023

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.

Copy link
Member

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);
Copy link
Member

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.

Copy link
Author

vmarkovtsev commented Aug 18, 2023
edited
Loading

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.

Copy link
Member

elprans commented Oct 9, 2023

OK, we seem to have different use cases and motivations with the maintainer here

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.

matthiasschaub reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@elprans elprans elprans left review comments

+1 more reviewer

@frake23 frake23 frake23 requested changes

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

cant pickle asyncpg.record

AltStyle によって変換されたページ (->オリジナル) /