MagicStack / MagicStack/asyncpg

Cannot create type codec for composite type with certain field types.

Open
#1,267 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.1k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

Hello, I noticed I can't create a type codec for a composite type if it has a field of type `json`, a `jsonb` or a `geometry` type. Why is so and is there a way to sidestep this issue?
```python
import json
from dataclasses import dataclass

@dataclass
class Foo:
data: dict

await conn.execute("CREATE TABLE foo (data jsonb NOT NULL);")

await conn.set_type_codec(
"foo",
schema="public",
encoder=lambda foo: (json.dumps(foo.data),),
decoder=lambda row: Foo(json.loads(row)),
format="tuple",
)
```
```python
UnsupportedClientFeatureError: cannot decode type "public"."foo": text encoding of composite types is not supported
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example through conn.set_type_codec with a composite type containing a jsonb field, then inspect the composite codec handling and PostgreSQL type-format constraints. Done means establishing support for the reported field types or clearly documenting the limitation and a supported workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.