]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
oid inits at compilation time/when needed again, added a unit test
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 28 Feb 2006 23:18:43 +0000 (23:18 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 28 Feb 2006 23:18:43 +0000 (23:18 +0000)
lib/sqlalchemy/ext/proxy.py
lib/sqlalchemy/sql.py
test/proxy_engine.py

index d9a830c66ebd65a707315df2f9fb561a17f18bc8..783ea969e8452478a3da90f81a6378152106c5c1 100644 (file)
@@ -28,10 +28,8 @@ class BaseProxyEngine(object):
         return "%s(%s)" % (self.__class__.__name__, id(self))
 
     def oid_column_name(self):
-        # NOTE: setting up mappers fails unless the proxy engine returns
-        # something for oid column name, and the call happens too early
-        # to proxy, so effecticely no oids are allowed when using
-        # proxy engine
+        # oid_column should not be requested before the engine is connected.
+        # it should ideally only be called at query compilation time.
         e= self.get_engine()
         if e is None:
             return None
index f905da583494dc0a5a4a5351972667112ad4455b..6b574861be8d0f9166cb7eebc4030237125f3136 100644 (file)
@@ -827,7 +827,9 @@ class Join(FromClause):
         else:
             self.onclause = onclause
         self.isouter = isouter
-        self.oid_column = self.left.oid_column
+
+    oid_column = property(lambda s:s.left.oid_column)
+    
     def _exportable_columns(self):
         return [c for c in self.left.columns] + [c for c in self.right.columns]
     def _proxy_column(self, column):
@@ -1001,6 +1003,7 @@ class TableClause(FromClause):
             if self.engine.oid_column_name() is not None:
                 self._oid_column = schema.Column(self.engine.oid_column_name(), sqltypes.Integer, hidden=True)
                 self._oid_column._set_parent(self)
+                self._orig_columns()[self._oid_column.original] = self._oid_column
             else:
                 self._oid_column = None
         return self._oid_column
@@ -1011,9 +1014,6 @@ class TableClause(FromClause):
             self._orig_cols= {}
             for c in self.columns:
                 self._orig_cols[c.original] = c
-            oid = self.oid_column
-            if oid is not None:
-                self._orig_cols[oid.original] = oid
             return self._orig_cols
     columns = property(lambda s:s._columns)
     c = property(lambda s:s._columns)
index 2ef19fc075c92e5265a590dbfdd4afc919cc0cf5..14cd1902bc7cca00a0d7205a152d109ce74e473f 100644 (file)
@@ -22,6 +22,17 @@ class User(object):
     pass
 
 
+class ConstructTest(PersistTest):
+    """tests that we can build SQL constructs without engine-specific parameters, particulary
+    oid_column, being needed, as the proxy engine is usually not connected yet."""
+    def test_join(self):
+        engine = ProxyEngine()
+        t = Table('table1', engine, 
+            Column('col1', Integer, primary_key=True))
+        t2 = Table('table2', engine, 
+            Column('col2', Integer, ForeignKey('table1.col1')))
+        j = join(t, t2)
+        
 class ProxyEngineTest1(PersistTest):
 
     def setUp(self):