+++ /dev/null
-.. change::
- :tags: postgresql, usecase, asyncpg
- :tickets: 7284
- :versions: 2.0.0b1
-
- Modified the asyncpg dialect to gracefully degrade types that are
- not supported by PostgreSQL work-alike databases. For example,
- CockroachDB supports JSONB but not JSON. Third-party dialects that
- are derived from ``PGDialect_asyncpg`` will no longer have to
- work around ValueError being raised by trying to register a codec
- for an unsupported type.
use_native_uuid = True
- _exclude_type_codecs = util.EMPTY_SET
-
colspecs = util.update_copy(
PGDialect.colspecs,
{
See https://github.com/MagicStack/asyncpg/issues/623 for reference
on why it's set up this way.
- See #7284 for the rationale behind adding
- self._exclude_type_codecs
-
"""
-
- if "json" not in self._exclude_type_codecs:
- try:
- await conn._connection.set_type_codec(
- "json",
- encoder=str.encode,
- decoder=_json_decoder,
- schema="pg_catalog",
- format="binary",
- )
- except ValueError:
- self._exclude_type_codecs |= {"json"}
-
- if "jsonb" not in self._exclude_type_codecs:
- try:
- await conn._connection.set_type_codec(
- "jsonb",
- encoder=_jsonb_encoder,
- decoder=_jsonb_decoder,
- schema="pg_catalog",
- format="binary",
- )
- except ValueError:
- self._exclude_type_codecs |= {"jsonb"}
+ await conn._connection.set_type_codec(
+ "json",
+ encoder=str.encode,
+ decoder=_json_decoder,
+ schema="pg_catalog",
+ format="binary",
+ )
+ await conn._connection.set_type_codec(
+ "jsonb",
+ encoder=_jsonb_encoder,
+ decoder=_jsonb_decoder,
+ schema="pg_catalog",
+ format="binary",
+ )
def connect(conn):
conn.await_(_setup_type_codecs(conn))