]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- PG reflection, upon seeing the default schema name being used explicitly
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 14 Oct 2007 19:15:09 +0000 (19:15 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 14 Oct 2007 19:15:09 +0000 (19:15 +0000)
  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.

CHANGES
lib/sqlalchemy/databases/postgres.py
test/engine/reflection.py

diff --git a/CHANGES b/CHANGES
index 7f1543e8685aeb8f688adb45d7706b3814dda2a3..cebf107c7d431cc949d89d071ea76d39825d61ff 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -38,6 +38,14 @@ CHANGES
 - 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]
index d894b1f2cfec1c64230c6c9c34f850b26bca6fc4..ddf6a6b9ce8aaf5105f57adbf668d47e6ac8ff98 100644 (file)
@@ -545,6 +545,11 @@ class PGDialect(default.DefaultDialect):
             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)]
 
index 82a04874afcd2748043fee8d11136e5bfcb9329a..4f1d18d5d2bbfa436146775db44d856289e8b99a 100644 (file)
@@ -696,7 +696,7 @@ class UnicodeTest(PersistTest):
 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),
@@ -719,10 +719,8 @@ class SchemaTest(PersistTest):
         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