From 362c9277b2d4d27cbcff359ba29c1e71005fed18 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 16 Sep 2020 08:26:14 -0400 Subject: Don't change asyncpg's "char" codec This codec was used to ensure the "pg_attribute.generated" column comes back as a string and not bytes, matching how other PG drivers treat this datatype. However, this breaks asyncpg's internal implementation of set_type_codec going forward and the "char" datatype is actually a bytes in any case. So at the moment it appears psycopg2/pg8000 are broken for mis-treatment of the datatype and asyncpg is broken in that it was allowing us to change a codec that it appears to rely upon internally. Fixes: #5586 Change-Id: I937eba315904721aa4e2726b95432910a8affe5f --- lib/sqlalchemy/dialects/postgresql/asyncpg.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/asyncpg.py') diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py index 780e23844..6fa1dd78b 100644 --- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py +++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py @@ -486,28 +486,13 @@ class AsyncAdapt_asyncpg_connection: async def _setup_type_codecs(self): """set up type decoders at the asyncpg level. - this is first to accommodate the "char" value of - pg_catalog.pg_attribute.attgenerated being returned as bytes. - Even though the doc at - https://magicstack.github.io/asyncpg/current/usage.html#type-conversion - claims "char" is returned as "str", it looks like this is actually - the 'bpchar' datatype, blank padded. 'char' seems to be some - more obscure type (oid 18) and asyncpg codes this to bytea: - https://github.com/MagicStack/asyncpg/blob/master/asyncpg/protocol/ - codecs/pgproto.pyx#L26 - - all the other drivers treat this as a string. + these are set_type_codec() calls to normalize + There was a tentative decoder for the "char" datatype here + to have it return strings however this type is actually a binary + type that other drivers are likely mis-interpreting. """ - await self._connection.set_type_codec( - "char", - schema="pg_catalog", - encoder=lambda value: value, - decoder=lambda value: value, - format="text", - ) - def _handle_exception(self, error): if not isinstance(error, AsyncAdapt_asyncpg_dbapi.Error): exception_mapping = self.dbapi._asyncpg_error_translate -- cgit v1.2.1