From fff90799098bd14ea68c158c787585f6dec130d4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 18 Oct 2013 19:00:05 -0400 Subject: [PATCH] - Removed a 128-character truncation from the reflection of the server default for a column; this code was original from PG system views which truncated the string for readability. [ticket:2844] --- doc/build/changelog/changelog_08.rst | 9 +++++++++ lib/sqlalchemy/dialects/postgresql/base.py | 3 +-- test/dialect/postgresql/test_reflection.py | 11 +++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 7a3909a9a2..126f3a3b8e 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -10,6 +10,15 @@ .. changelog:: :version: 0.8.3 + .. change:: + :tags: bug, postgresql + :tickets: 2844 + :versions: 0.9.0 + + Removed a 128-character truncation from the reflection of the + server default for a column; this code was original from + PG system views which truncated the string for readability. + .. change:: :tags: bug, mysql :tickets: 2721, 2839 diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 5efa2e983f..fdb6e3b4a6 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1687,8 +1687,7 @@ class PGDialect(default.DefaultDialect): SQL_COLS = """ SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod), - (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) - for 128) + (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid) FROM pg_catalog.pg_attrdef d WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index fb399b5461..1f2c1e94bf 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -159,6 +159,17 @@ class ReflectionTest(fixtures.TestBase): subject.join(referer).onclause)) @testing.provide_metadata + def test_reflect_default_over_128_chars(self): + Table('t', self.metadata, + Column('x', String(200), server_default="abcd" * 40) + ).create(testing.db) + + m = MetaData() + t = Table('t', m, autoload=True, autoload_with=testing.db) + eq_( + t.c.x.server_default.arg.text, "'%s'::character varying" % ("abcd" * 40) + ) + @testing.provide_metadata def test_renamed_sequence_reflection(self): metadata = self.metadata t = Table('t', metadata, Column('id', Integer, primary_key=True)) -- 2.47.3