]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- some test fixes
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 19 Jan 2014 05:34:37 +0000 (00:34 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 19 Jan 2014 05:34:37 +0000 (00:34 -0500)
- clean up some shenanigans in reflection

lib/sqlalchemy/dialects/oracle/base.py
lib/sqlalchemy/engine/reflection.py
test/orm/test_expire.py
test/sql/test_metadata.py

index 74a587d0bbb3df635889b79292e7458564d9ecae..218a7ccfcea385f7671147c3dfcbaf8c3414cc94 100644 (file)
@@ -181,7 +181,7 @@ from sqlalchemy import util, sql
 from sqlalchemy.engine import default, base, reflection
 from sqlalchemy.sql import compiler, visitors, expression
 from sqlalchemy.sql import operators as sql_operators, functions as sql_functions
-from sqlalchemy import types as sqltypes
+from sqlalchemy import types as sqltypes, schema as sa_schema
 from sqlalchemy.types import VARCHAR, NVARCHAR, CHAR, DATE, DATETIME, \
                 BLOB, CLOB, TIMESTAMP, FLOAT
 
@@ -754,7 +754,9 @@ class OracleDialect(default.DefaultDialect):
 
     reflection_options = ('oracle_resolve_synonyms', )
 
-    construct_arguments = []
+    construct_arguments = [
+        (sa_schema.Table, {"resolve_synonyms": False})
+    ]
 
     def __init__(self,
                 use_ansi=True,
index 93b66bf0cb8c4041f8d1890455dbcd7d1f765df5..d82aac7fdd69a90a34aa9f0da80f2b8109bc48ba 100644 (file)
@@ -431,37 +431,36 @@ class Inspector(object):
         """
         dialect = self.bind.dialect
 
-        # table attributes we might need.
-        reflection_options = dict(
-            (k, table.kwargs.get(k))
-            for k in dialect.reflection_options if k in table.kwargs)
-
         schema = table.schema
         table_name = table.name
 
-        # apply table options
-        tbl_opts = self.get_table_options(table_name, schema, **table.kwargs)
+        # get table-level arguments that are specifically
+        # intended for reflection, e.g. oracle_resolve_synonyms.
+        # these are unconditionally passed to related Table
+        # objects
+        reflection_options = dict(
+            (k, table.dialect_kwargs.get(k))
+            for k in dialect.reflection_options
+            if k in table.dialect_kwargs
+        )
+
+        # reflect table options, like mysql_engine
+        tbl_opts = self.get_table_options(table_name, schema, **table.dialect_kwargs)
         if tbl_opts:
+            # add additional kwargs to the Table if the dialect
+            # returned them
             table._validate_dialect_kwargs(tbl_opts)
 
-        # table.kwargs will need to be passed to each reflection method.  Make
-        # sure keywords are strings.
-        tblkw = table.kwargs.copy()
-        for (k, v) in list(tblkw.items()):
-            del tblkw[k]
-            tblkw[str(k)] = v
-
         if util.py2k:
             if isinstance(schema, str):
                 schema = schema.decode(dialect.encoding)
             if isinstance(table_name, str):
                 table_name = table_name.decode(dialect.encoding)
 
-        # columns
         found_table = False
         cols_by_orig_name = {}
 
-        for col_d in self.get_columns(table_name, schema, **tblkw):
+        for col_d in self.get_columns(table_name, schema, **table.dialect_kwargs):
             found_table = True
             orig_name = col_d['name']
 
@@ -474,12 +473,12 @@ class Inspector(object):
                 continue
 
             coltype = col_d['type']
-            col_kw = {
-                'nullable': col_d['nullable'],
-            }
-            for k in ('autoincrement', 'quote', 'info', 'key'):
-                if k in col_d:
-                    col_kw[k] = col_d[k]
+
+            col_kw = dict(
+                (k, col_d[k])
+                for k in ['nullable', 'autoincrement', 'quote', 'info', 'key']
+                if k in col_d
+            )
 
             colargs = []
             if col_d.get('default') is not None:
@@ -510,8 +509,7 @@ class Inspector(object):
         if not found_table:
             raise exc.NoSuchTableError(table.name)
 
-        # Primary keys
-        pk_cons = self.get_pk_constraint(table_name, schema, **tblkw)
+        pk_cons = self.get_pk_constraint(table_name, schema, **table.dialect_kwargs)
         if pk_cons:
             pk_cols = [
                 cols_by_orig_name[pk]
@@ -530,8 +528,7 @@ class Inspector(object):
 
             table.append_constraint(primary_key_constraint)
 
-        # Foreign keys
-        fkeys = self.get_foreign_keys(table_name, schema, **tblkw)
+        fkeys = self.get_foreign_keys(table_name, schema, **table.dialect_kwargs)
         for fkey_d in fkeys:
             conname = fkey_d['name']
             # look for columns by orig name in cols_by_orig_name,
index 292546e99807bce02a803bc56b5e9653d2b8648e..edd2431818b95ba666618b0c84341b92f13d9178 100644 (file)
@@ -375,7 +375,7 @@ class ExpireTest(_fixtures.FixtureTest):
         o = sess.query(Order).get(3)
         sess.expire(o)
 
-        orders.update(id=3).execute(description='order 3 modified')
+        orders.update().execute(description='order 3 modified')
         assert o.isopen == 1
         assert attributes.instance_state(o).dict['description'] == 'order 3 modified'
         def go():
index c450011060fd1a9f17ebc504d3e4662d084038d6..91a5a26004417f198403bb8602cd1c995f5fc23c 100644 (file)
@@ -6,8 +6,8 @@ import pickle
 from sqlalchemy import Integer, String, UniqueConstraint, \
     CheckConstraint, ForeignKey, MetaData, Sequence, \
     ForeignKeyConstraint, ColumnDefault, Index, event,\
-    events, Unicode, types as sqltypes, bindparam
-from sqlalchemy.testing.schema import Table, Column
+    events, Unicode, types as sqltypes, bindparam, \
+    Table, Column
 from sqlalchemy import schema, exc
 import sqlalchemy as tsa
 from sqlalchemy.testing import fixtures
@@ -308,6 +308,7 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
 
     @testing.exclude('mysql', '<', (4, 1, 1), 'early types are squirrely')
     def test_to_metadata(self):
+        from sqlalchemy.testing.schema import Table
         meta = MetaData()
 
         table = Table('mytable', meta,
@@ -320,7 +321,7 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
             Column('description', String(30),
                                     CheckConstraint("description='hi'")),
             UniqueConstraint('name'),
-            test_needs_fk=True,
+            test_needs_fk=True
         )
 
         table2 = Table('othertable', meta,
@@ -328,7 +329,7 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
             Column('myid', Integer,
                         ForeignKey('mytable.myid'),
                     ),
-            test_needs_fk=True,
+            test_needs_fk=True
             )
 
         def test_to_metadata():
@@ -487,13 +488,11 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
             Column('description', String(30),
                             CheckConstraint("description='hi'")),
             UniqueConstraint('name'),
-            test_needs_fk=True,
         )
 
         table2 = Table('othertable', meta,
             Column('id', Integer, primary_key=True),
             Column('myid', Integer, ForeignKey('mytable.myid')),
-            test_needs_fk=True,
             )
 
         meta2 = MetaData()
@@ -514,14 +513,12 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
             Column('description', String(30),
                         CheckConstraint("description='hi'")),
             UniqueConstraint('name'),
-            test_needs_fk=True,
             schema='myschema',
         )
 
         table2 = Table('othertable', meta,
             Column('id', Integer, primary_key=True),
             Column('myid', Integer, ForeignKey('myschema.mytable.myid')),
-            test_needs_fk=True,
             schema='myschema',
             )
 
@@ -699,13 +696,11 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
             Column('name', String(40), nullable=True),
             Column('description', String(30), CheckConstraint("description='hi'")),
             UniqueConstraint('name'),
-            test_needs_fk=True
         )
 
         table2 = Table('othertable', meta,
             Column('id', Integer, primary_key=True),
             Column('myid', Integer, ForeignKey('myschema.mytable.myid')),
-            test_needs_fk=True
             )
 
         meta2 = MetaData(schema='someschema')
@@ -726,13 +721,11 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
             Column('description', String(30),
                         CheckConstraint("description='hi'")),
             UniqueConstraint('name'),
-            test_needs_fk=True,
         )
 
         table2 = Table('othertable', meta,
             Column('id', Integer, primary_key=True),
             Column('myid', Integer, ForeignKey('mytable.myid')),
-            test_needs_fk=True,
             )
 
         meta2 = MetaData()