From c124fa36d5af2c85c87c51d24e92387adffbe3d2 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 18 May 2016 11:07:02 -0400 Subject: Support "blank" schema when MetaData.schema is set Previously, it was impossible to have a Table that has None for a schema name when the "schema" parameter on MetaData was set. A new symbol sqlalchemy.schema.BLANK_SCHEMA is added which indicates that the schema name should unconditionally be set to None. In particular, this value must be passed within cross-schema foreign key reflection, so that a Table which is in the "default" schema can be represented properly. Fixes: #3716 Change-Id: I3d24f99c22cded206c5379fd32a225e74edb7a8e --- test/dialect/postgresql/test_reflection.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/dialect/postgresql/test_reflection.py') diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index 8da18108f..4897c4a7e 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -581,6 +581,29 @@ class ReflectionTest(fixtures.TestBase): eq_(set(meta3.tables), set( ['test_schema_2.some_other_table', 'test_schema.some_table'])) + @testing.provide_metadata + def test_cross_schema_reflection_metadata_uses_schema(self): + # test [ticket:3716] + + metadata = self.metadata + + Table('some_table', metadata, + Column('id', Integer, primary_key=True), + Column('sid', Integer, ForeignKey('some_other_table.id')), + schema='test_schema' + ) + Table('some_other_table', metadata, + Column('id', Integer, primary_key=True), + schema=None + ) + metadata.create_all() + with testing.db.connect() as conn: + meta2 = MetaData(conn, schema="test_schema") + meta2.reflect() + + eq_(set(meta2.tables), set( + ['some_other_table', 'test_schema.some_table'])) + @testing.provide_metadata def test_uppercase_lowercase_table(self): metadata = self.metadata -- cgit v1.2.1