diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-07 11:12:31 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-11 14:20:10 -0400 |
commit | aceefb508ccd0911f52ff0e50324b3fefeaa3f16 (patch) | |
tree | e57124d3ea8b0e2cd7fe1d3ad22170fa956bcafb /test/engine/test_reflection.py | |
parent | 5c16367ee78fa1a41d6b715152dcc58f45323d2e (diff) | |
download | sqlalchemy-aceefb508ccd0911f52ff0e50324b3fefeaa3f16.tar.gz |
Allow duplicate columns in from clauses and selectables
The :func:`.select` construct and related constructs now allow for
duplication of column labels and columns themselves in the columns clause,
mirroring exactly how column expressions were passed in. This allows
the tuples returned by an executed result to match what was SELECTed
for in the first place, which is how the ORM :class:`.Query` works, so
this establishes better cross-compatibility between the two constructs.
Additionally, it allows column-positioning-sensitive structures such as
UNIONs (i.e. :class:`.CompoundSelect`) to be more intuitively constructed
in those cases where a particular column might appear in more than one
place. To support this change, the :class:`.ColumnCollection` has been
revised to support duplicate columns as well as to allow integer index
access.
Fixes: #4753
Change-Id: Ie09a8116f05c367995c1e43623c51e07971d3bf0
Diffstat (limited to 'test/engine/test_reflection.py')
-rw-r--r-- | test/engine/test_reflection.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 1cabf8963..f6c19047e 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -280,6 +280,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): # test against a table which is already reflected meta3 = MetaData(testing.db) foo = Table("foo", meta3, autoload=True) + foo = Table( "foo", meta3, include_columns=["b", "f", "e"], extend_existing=True ) @@ -308,7 +309,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): old_y = Column("y", String) old_q = Column("q", Integer) t2 = Table("t", m2, old_z, old_q) - eq_(t2.primary_key.columns, (t2.c.z,)) + eq_(list(t2.primary_key.columns), [t2.c.z]) t2 = Table( "t", m2, @@ -318,7 +319,11 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): autoload_with=testing.db, ) eq_(set(t2.columns.keys()), set(["x", "y", "z", "q", "id"])) - eq_(t2.primary_key.columns, (t2.c.id,)) + + # this has been the actual behavior, the cols are added together, + # however the test wasn't checking this correctly + eq_(list(t2.primary_key.columns), [t2.c.z, t2.c.id]) + assert t2.c.z is not old_z assert t2.c.y is old_y assert t2.c.z.type._type_affinity is Integer @@ -340,7 +345,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): old_y = Column("y", String) old_q = Column("q", Integer) t4 = Table("t", m4, old_z, old_q) - eq_(t4.primary_key.columns, (t4.c.z,)) + eq_(list(t4.primary_key.columns), [t4.c.z]) t4 = Table( "t", m4, @@ -351,7 +356,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): autoload_with=testing.db, ) eq_(set(t4.columns.keys()), set(["x", "y", "z", "q", "id"])) - eq_(t4.primary_key.columns, (t4.c.id,)) + eq_(list(t4.primary_key.columns), [t4.c.z, t4.c.id]) assert t4.c.z is old_z assert t4.c.y is old_y assert t4.c.z.type._type_affinity is String @@ -770,6 +775,9 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): ), autoload=True, ) + + # for the thing happening here with the column collection, + # see test/base/test_utils.py-> test_replace_switch_key_name. assert u4.join(a4).onclause.compare(u4.c.u_id == a4.c.id) assert list(u4.primary_key) == [u4.c.u_id] assert len(u4.columns) == 2 |