]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug that would prevent overridden clause
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 Jun 2010 21:20:17 +0000 (17:20 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 Jun 2010 21:20:17 +0000 (17:20 -0400)
compilation from working for "annotated" expression
elements, which are often generated by the ORM.

CHANGES
lib/sqlalchemy/sql/util.py
test/ext/test_compiler.py

diff --git a/CHANGES b/CHANGES
index 9c983e1c8898c202a0d8a5cae8970bfbd85acaa3..aba313a7ce7c5c741d616dfcb5028cc56d8c4cab 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -60,6 +60,10 @@ CHANGES
     and large string values don't pollute the output.
     [ticket:1822]
 
+  - Fixed bug that would prevent overridden clause
+    compilation from working for "annotated" expression
+    elements, which are often generated by the ORM.
+    
   - The argument to "ESCAPE" of a LIKE operator or similar
     is passed through render_literal_value(), which may 
     implement escaping of backslashes.  [ticket:1400]
index d0af0a9d6e8f7055c54a1694bbc32cc82f8ca8e7..c999ab7862a28c0fd76fc5b0f370b0d4ebb4a85e 100644 (file)
@@ -259,7 +259,7 @@ class Annotated(object):
         self.__dict__ = element.__dict__.copy()
         self.__element = element
         self._annotations = values
-
+        
     def _annotate(self, values):
         _values = self._annotations.copy()
         _values.update(values)
@@ -270,7 +270,10 @@ class Annotated(object):
     
     def _deannotate(self):
         return self.__element
-
+    
+    def _compiler_dispatch(self, visitor, **kw):
+        return self.__element.__class__._compiler_dispatch(self, visitor, **kw)
+        
     @property
     def _constructor(self):
         return self.__element._constructor
@@ -300,7 +303,6 @@ annotated_classes = {}
 for cls in expression.__dict__.values() + [schema.Column, schema.Table]:
     if isinstance(cls, type) and issubclass(cls, expression.ClauseElement):
         exec "class Annotated%s(Annotated, cls):\n" \
-             "    __visit_name__ = cls.__visit_name__\n"\
              "    pass" % (cls.__name__, ) in locals()
         exec "annotated_classes[cls] = Annotated%s" % (cls.__name__)
 
index 2d33b382afededc9059c64491b0bc3a02f724356..fa1e3c1623e5efbaf115b5379e418d3f13d469f0 100644 (file)
@@ -1,7 +1,7 @@
 from sqlalchemy import *
 from sqlalchemy.types import TypeEngine
 from sqlalchemy.sql.expression import ClauseElement, ColumnClause,\
-                                    FunctionElement
+                                    FunctionElement, Select
 from sqlalchemy.schema import DDLElement
 from sqlalchemy.ext.compiler import compiles
 from sqlalchemy.sql import table, column
@@ -98,9 +98,34 @@ class UserDefinedTest(TestBase, AssertsCompiledSQL):
                 t1,
                 select([t1]).where(t1.c.x>5)
             ),
-            "INSERT INTO mytable (SELECT mytable.x, mytable.y, mytable.z FROM mytable WHERE mytable.x > :x_1)"
+            "INSERT INTO mytable (SELECT mytable.x, mytable.y, mytable.z "
+            "FROM mytable WHERE mytable.x > :x_1)"
         )
-
+    
+    def test_annotations(self):
+        """test that annotated clause constructs use the 
+        decorated class' compiler.
+        
+        """
+        t1 = table('t1', column('c1'), column('c2'))
+        
+        dispatch = Select._compiler_dispatch
+        try:
+            @compiles(Select)
+            def compile(element, compiler, **kw):
+                return "OVERRIDE"
+            
+            s1 = select([t1])
+            self.assert_compile(
+                s1, "OVERRIDE"
+            )
+            self.assert_compile(
+                s1._annotate({}),
+                "OVERRIDE"
+            )
+        finally:
+            Select._compiler_dispatch = dispatch
+            
     def test_dialect_specific(self):
         class AddThingy(DDLElement):
             __visit_name__ = 'add_thingy'