Commits

Mike Bayer committed 45e0ff6

- PG reflection, upon seeing the default schema name being used explicitly
as the "schema" argument in a Table, will assume that this is the the
user's desired convention, and will explicitly set the "schema" argument
in foreign-key-related reflected tables, thus making them match only
with Table constructors that also use the explicit "schema" argument
(even though its the default schema).
In other words, SA assumes the user is being consistent in this usage.

  • Participants
  • Parent commits de11954

Comments (0)

Files changed (3)

 - Added support for returning values from inserts and udpates for
   PostgreSQL 8.2+. [ticket:797]
 
+- PG reflection, upon seeing the default schema name being used explicitly
+  as the "schema" argument in a Table, will assume that this is the the 
+  user's desired convention, and will explicitly set the "schema" argument
+  in foreign-key-related reflected tables, thus making them match only
+  with Table constructors that also use the explicit "schema" argument
+  (even though its the default schema).  
+  In other words, SA assumes the user is being consistent in this usage.
+  
 - fixed sqlite reflection of BOOL/BOOLEAN [ticket:808]
 
 - null foreign key on a m2o doesn't trigger a lazyload [ticket:803]

lib/sqlalchemy/databases/postgres.py

             constrained_columns = [preparer._unquote_identifier(x) for x in re.split(r'\s*,\s*', constrained_columns)]
             if referred_schema:
                 referred_schema = preparer._unquote_identifier(referred_schema)
+            elif table.schema is not None and table.schema == self.get_default_schema_name(connection):
+                # no schema (i.e. its the default schema), and the table we're 
+                # reflecting has the default schema explicit, then use that.
+                # i.e. try to use the user's conventions
+                referred_schema = table.schema
             referred_table = preparer._unquote_identifier(referred_table)
             referred_columns = [preparer._unquote_identifier(x) for x in re.split(r'\s*,\s', referred_columns)]
 

test/engine/reflection.py

 class SchemaTest(PersistTest):
     # this test should really be in the sql tests somewhere, not engine
     @testing.unsupported('sqlite', 'firebird')
-    def testiteration(self):
+    def test_iteration(self):
         metadata = MetaData()
         table1 = Table('table1', metadata,
             Column('col1', Integer, primary_key=True),
         assert buf.index("CREATE TABLE someschema.table1") > -1
         assert buf.index("CREATE TABLE someschema.table2") > -1
 
-    # TODO: figure out why postgres screws up on this test
-    #@testing.supported('mysql','postgres')
-    @testing.supported('mysql')
-    def testcreate(self):
+    @testing.supported('mysql','postgres')
+    def test_explicit_default_schema(self):
         engine = testbase.db
         schema = engine.dialect.get_default_schema_name(engine)
         #engine.echo = True