From 5c48094cbde3cbfaaed0b137ced4887bef14dc29 Mon Sep 17 00:00:00 2001 From: Gord Thompson Date: Mon, 7 Oct 2024 06:31:22 -0600 Subject: [PATCH] Apply fix to reflection of table comments Fixes: #11961 Change-Id: Ia3e704973a17cdf5c45bb5b8127435ee562c7d15 --- doc/build/changelog/unreleased_20/11961.rst | 7 +++++++ lib/sqlalchemy/dialects/postgresql/base.py | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 doc/build/changelog/unreleased_20/11961.rst diff --git a/doc/build/changelog/unreleased_20/11961.rst b/doc/build/changelog/unreleased_20/11961.rst new file mode 100644 index 0000000000..c6ffceb036 --- /dev/null +++ b/doc/build/changelog/unreleased_20/11961.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, postgresql, reflection + :tickets: 11961 + + Fixed bug in reflection of table comments where unrelated text would be + returned if an entry in the pg_description table happened to share the + same oid (objoid) as the table being reflected. \ No newline at end of file diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 4b9f2f0150..86357ccbb4 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -4689,6 +4689,8 @@ class PGDialect(default.DefaultDialect): pg_catalog.pg_class.c.oid == pg_catalog.pg_description.c.objoid, pg_catalog.pg_description.c.objsubid == 0, + pg_catalog.pg_description.c.classoid + == sql.func.cast("pg_catalog.pg_class", REGCLASS), ), ) .where(self._pg_class_relkind_condition(relkinds)) -- 2.47.3