]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Modified the internals of "column annotation" such that
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Jun 2010 23:39:26 +0000 (19:39 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Jun 2010 23:39:26 +0000 (19:39 -0400)
a custom Column subclass can safely override
_constructor to return Column, for the purposes of
making "configurational" column classes that aren't
involved in proxying, etc.

CHANGES
lib/sqlalchemy/sql/util.py
test/sql/test_selectable.py

diff --git a/CHANGES b/CHANGES
index 714f82bab172654fa8c0d9c1bd143cedad91be00..94e4961c5cbe331d1f6c87cd208366963e0444e4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -29,6 +29,12 @@ CHANGES
     initialize has been called.  the internal name ".conn"
     is changed to ".bind", since that's what it is.
     
+  - Modified the internals of "column annotation" such that
+    a custom Column subclass can safely override
+    _constructor to return Column, for the purposes of 
+    making "configurational" column classes that aren't 
+    involved in proxying, etc.
+    
 - firebird
   - Fixed incorrect signature in do_execute(), error 
     introduced in 0.6.1. [ticket:1823]
index 14ea42d2c723c9c094522e193a11bf63cf2eebe7..d0af0a9d6e8f7055c54a1694bbc32cc82f8ca8e7 100644 (file)
@@ -273,7 +273,7 @@ class Annotated(object):
 
     @property
     def _constructor(self):
-        return self.__element.__class__
+        return self.__element._constructor
         
     def _clone(self):
         clone = self.__element._clone()
index 13f629e28827a95740aadae90b7b44785e0d2670..2537c489652ebe5f1331d61326117a0cece01ab4 100644 (file)
@@ -598,6 +598,24 @@ class DerivedTest(TestBase, AssertsExecutionResults):
         assert not t2.select().alias('foo').is_derived_from(t1)
 
 class AnnotationsTest(TestBase):
+    def test_custom_constructions(self):
+        from sqlalchemy.schema import Column
+        class MyColumn(Column):
+            def __init__(self):
+                Column.__init__(self, 'foo', Integer)
+            _constructor = Column
+            
+        t1 = Table('t1', MetaData(), MyColumn())
+        s1 = t1.select()
+        assert isinstance(t1.c.foo, MyColumn)
+        assert isinstance(s1.c.foo, Column)
+
+        annot_1 = t1.c.foo._annotate({})
+        s2 = select([annot_1])
+        assert isinstance(s2.c.foo, Column)
+        annot_2 = s1._annotate({})
+        assert isinstance(annot_2.c.foo, Column)
+        
     def test_annotated_corresponding_column(self):
         table1 = table('table1', column("col1"))