]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed mysql FK reflection for the edge case where a Table has expicitly provided...
authorJason Kirtland <jek@discorporate.us>
Mon, 27 Oct 2008 22:56:53 +0000 (22:56 +0000)
committerJason Kirtland <jek@discorporate.us>
Mon, 27 Oct 2008 22:56:53 +0000 (22:56 +0000)
CHANGES
lib/sqlalchemy/databases/mysql.py
test/engine/reflection.py

diff --git a/CHANGES b/CHANGES
index 7518c61c2f15267cadb5c6b53c01cdddf7d8d23c..17f943adea838c83ed8c0aeda66d6eb9d28e7549 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,74 +7,75 @@ CHANGES
 0.5.0rc3
 ========
 - orm
-    - "not equals" comparisons of simple many-to-one relation
-      to an instance will not drop into an EXISTS clause
-      and will compare foreign key columns instead.
-  
-    - removed not-really-working use cases of comparing 
-      a collection to an iterable.  Use contains() to test
-      for collection membership.
-
-    - Improved weakref identity map memory management to no longer 
-      require mutexing, resurrects garbage collected instance
-      on a lazy basis for an InstanceState with pending changes.
+    - "not equals" comparisons of simple many-to-one relation to an
+      instance will not drop into an EXISTS clause and will compare
+      foreign key columns instead.
+
+    - Removed not-really-working use cases of comparing a collection
+      to an iterable.  Use contains() to test for collection
+      membership.
+
+    - Improved weakref identity map memory management to no longer
+      require mutexing, resurrects garbage collected instance on a
+      lazy basis for an InstanceState with pending changes.
 
     - relation() won't hide unrelated ForeignKey errors inside of
-      the "please specify primaryjoin" message when determining
-      join condition.
-     
-    - When using Query.join() with an explicit clause for the 
-      ON clause, the clause will be aliased in terms of the left
-      side of the join, allowing scenarios like query(Source).
+      the "please specify primaryjoin" message when determining join
+      condition.
+
+    - When using Query.join() with an explicit clause for the ON
+      clause, the clause will be aliased in terms of the left side
+      of the join, allowing scenarios like query(Source).
       from_self().join((Dest, Source.id==Dest.source_id)) to work
       properly.
-      
-    - polymorphic_union() function respects the "key" of each 
-      Column if they differ from the column's name.
-
-    - Added more granularity to internal attribute access, such 
-      that cascade and flush operations will not initialize
-      unloaded attributes and collections, leaving them intact for
-      a lazy-load later on.  Backref events still initialize 
-      attrbutes and collections for pending instances.
-      [ticket:1202]
-    
-    - InstanceState object now removes circular references to 
-      itself upon disposal to keep it outside of cyclic garbage
-      collection.
-      
+
+    - polymorphic_union() function respects the "key" of each Column
+      if they differ from the column's name.
+
+    - Added more granularity to internal attribute access, such that
+      cascade and flush operations will not initialize unloaded
+      attributes and collections, leaving them intact for a
+      lazy-load later on.  Backref events still initialize attrbutes
+      and collections for pending instances.  [ticket:1202]
+
+    - InstanceState object now removes circular references to itself
+      upon disposal to keep it outside of cyclic garbage collection.
+
 - sql
-    - Further simplified SELECT compilation and its relationship
-      to result row processing.
+    - Further simplified SELECT compilation and its relationship to
+      result row processing.
 
     - Direct execution of a union() construct will properly set up
       result-row processing. [ticket:1194]
 
     - The internal notion of an "OID" or "ROWID" column has been
       removed.  It's basically not used by any dialect, and the
-      possibility of its usage with psycopg2's cursor.lastrowid
-      is basically gone now that INSERT..RETURNING is available.
-  
-    - Removed "default_order_by()" method on all FromClause
-      objects.
+      possibility of its usage with psycopg2's cursor.lastrowid is
+      basically gone now that INSERT..RETURNING is available.
+
+    - Removed "default_order_by()" method on all FromClause objects.
 
     - Slightly changed behavior of IN operator for comparing to
       empty collections. Now results in inequality comparison
-      against self. More portable, but breaks with stored
-      procedures that aren't pure functions.
+      against self. More portable, but breaks with stored procedures
+      that aren't pure functions.
 
 - oracle
     - Removed FIRST_ROWS() optimize flag when using LIMIT/OFFSET,
       can be reenabled with optimize_limits=True create_engine()
       flag.  [ticket:536]
 
-    - Wrote a docstring for Oracle dialect.  Apparently that
-      Ohloh "few source code comments" label is starting to sting
-      :).
+    - Wrote a docstring for Oracle dialect.  Apparently that Ohloh
+      "few source code comments" label is starting to sting :).
+
+    - Setting the auto_convert_lobs to False on create_engine() will
+      also instruct the OracleBinary type to return the cx_oracle
+      LOB object unchanged.
 
-    - Setting the auto_convert_lobs to False on create_engine()
-      will also instruct the OracleBinary type to return the
-      cx_oracle LOB object unchanged.
+- mysql
+    - Fixed foreign key reflection in the edge case where a Table's
+      explicit schema= is the same as the schema (database) the
+      connection is attached to.
 
 0.5.0rc2
 ========
index f1187b8ac678ab79ae92d483cba39606bed302e2..743ec96ea249b461807e8faae6a7f190c1f2c6eb 100644 (file)
@@ -2334,11 +2334,20 @@ class MySQLSchemaReflector(object):
     def _set_constraints(self, table, constraints, connection, only):
         """Apply constraints to a ``Table``."""
 
+        default_schema = None
+
         for spec in constraints:
             # only FOREIGN KEYs
             ref_name = spec['table'][-1]
             ref_schema = len(spec['table']) > 1 and spec['table'][-2] or None
 
+            if not ref_schema:
+                if default_schema is None:
+                    default_schema = connection.dialect.get_default_schema_name(
+                        connection)
+                if table.schema == default_schema:
+                    ref_schema = table.schema
+
             loc_names = spec['local']
             if only and not set(loc_names).issubset(only):
                 self.logger.info(
index 5916e8cadacf7e93b5ae349c712c95a75972e609..7963cc0e4ad9fca419a6d5ab3aeefc5dadbd4329 100644 (file)
@@ -696,19 +696,23 @@ class SchemaTest(TestBase):
         metadata = MetaData(engine)
         table1 = Table('table1', metadata,
                        Column('col1', sa.Integer, primary_key=True),
+                       test_needs_fk=True,
                        schema=schema)
         table2 = Table('table2', metadata,
                        Column('col1', sa.Integer, primary_key=True),
                        Column('col2', sa.Integer,
                               sa.ForeignKey('%s.table1.col1' % schema)),
+                       test_needs_fk=True,
                        schema=schema)
         try:
             metadata.create_all()
             metadata.create_all(checkfirst=True)
+            assert len(metadata.tables) == 2
             metadata.clear()
 
             table1 = Table('table1', metadata, autoload=True, schema=schema)
             table2 = Table('table2', metadata, autoload=True, schema=schema)
+            assert len(metadata.tables) == 2
         finally:
             metadata.drop_all()