From: Denis Laxalde Date: Tue, 22 Jul 2025 11:55:40 +0000 (+0200) Subject: Fix column collation reflection w.r.t. type's default in PostgreSQL X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5a0318c21fd8d800a23d2e39d4c66d7b051fb21e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix column collation reflection w.r.t. type's default in PostgreSQL The previous `if` clause was wrong as it would match the `else` branch if `default_collation_for_types` was `None` whereas we only want that branch to match if the type is in `default_collation_for_types` array. --- diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index a024d7b468..1d6bd20eb4 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -4034,19 +4034,18 @@ class PGDialect(default.DefaultDialect): table_cols = columns[(schema, row_dict["table_name"])] try: - collation_name, default_collation_for_types = collations[ + collation, default_collation_for_types = collations[ row_dict["collation"] ] except KeyError: collation = None else: # Only export the collation if distinct from type's default. - collation = ( - collation_name - if default_collation_for_types is not None - and row_dict["type"] not in default_collation_for_types - else None - ) + if ( + default_collation_for_types is not None + and row_dict["type"] in default_collation_for_types + ): + collation = None coltype = self._reflect_type( row_dict["format_type"],