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.

Assessment

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

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.

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?

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",
)
UnsupportedClientFeatureError: cannot decode type "public"."foo": text encoding of composite types is not supported
Dominant language
Python
Stars
8.1k
Forks
469
Avg merge
4h 42m
Merged PRs (30d)
6

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.

More from MagicStack/asyncpg

All issues in MagicStack/asyncpg

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.