From 5a0318c21fd8d800a23d2e39d4c66d7b051fb21e Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Tue, 22 Jul 2025 13:55:40 +0200 Subject: [PATCH] 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. --- lib/sqlalchemy/dialects/postgresql/base.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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"], -- 2.47.3