]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix column collation reflection w.r.t. type's default in PostgreSQL
authorDenis Laxalde <denis@laxalde.org>
Tue, 22 Jul 2025 11:55:40 +0000 (13:55 +0200)
committerDenis Laxalde <denis@laxalde.org>
Tue, 22 Jul 2025 11:55:40 +0000 (13:55 +0200)
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

index a024d7b46881b2ffefd1bc9eb49a3465382e5da7..1d6bd20eb4befcf9310c4f7a7874d58b94a61d1e 100644 (file)
@@ -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"],