Skip to content

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

@tvallotton

Description

@tvallotton

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions