MagicStack / MagicStack/asyncpg
Nested custom types in Postgres break `asyncpg.Record` subclassing
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.1k
- Forks
- 468
- PR merge metrics
- No merged PRs in 30d
Description
-
asyncpg version: v0.25.0
-
PostgreSQL version: 14
-
Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: on-premise -
Python version: 3.10.1
-
Platform: linux
-
Do you use pgbouncer?: no
-
Did you install asyncpg with pip?: yes
-
If you built asyncpg locally, which version of Cython did you use?: n/a
-
Can the issue be reproduced under both asyncio and
uvloop?: n/a
It would appear that nested types are not converted to a user specified record_class, and instead will always use asyncpg.Record.
For example:
CREATE TYPE my_custom_type AS (
id int,
filename text,
sql text
);
CREATE TABLE my_table (
files my_custom_type[] NOT NULL,
);
SELECT * FROM my_table
If you specify a custom record_class, then the record from SELECT * FROM my_table will be your subclass. However, the value inside record['files'] will use the asyncpg.Record class, rather than the custom one specified.
What should actually happen?
I think if a user specifies a record_class, then this class should always be used, even for nested custom types. It's quite unexpected behaviour for asyncpg to use the default class when a custom one has been specified.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the custom PostgreSQL type, array column, SELECT query, and a custom record_class described in the report. Trace how nested custom-type values are decoded and how record_class is propagated; done means records inside record['files'] use the specified subclass rather than asyncpg.Record, with regression coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100