MagicStack/asyncpg

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

Opened this issue · 0 comments

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