]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed bug whereby TypeDecorator would
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 28 Nov 2011 17:44:56 +0000 (12:44 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 28 Nov 2011 17:44:56 +0000 (12:44 -0500)
return a stale value for _type_affinity, when
using a TypeDecorator that "switches" types,
like the CHAR/UUID type.

CHANGES
lib/sqlalchemy/types.py
test/sql/test_types.py

diff --git a/CHANGES b/CHANGES
index bb2266f0c87909c0ac59bc805dc73ed85f0d0bfe..f3793cfc3354901ec8af95a646f5e43071a8954a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -124,6 +124,11 @@ CHANGES
       on dialect, but only works on Postgresql so far.
     Courtesy Manlio Perillo, [ticket:1679]
 
+  - [bug] Fixed bug whereby TypeDecorator would
+    return a stale value for _type_affinity, when
+    using a TypeDecorator that "switches" types,
+    like the CHAR/UUID type.
+
 - postgresql
    - [bug] Postgresql dialect memoizes that an ENUM of a 
      particular name was processed
index a4714d3d8370f4fefe69cd2cb68713abbc23f4da..79799da8f33b5078c1ff96696c7eea882ed8ff35 100644 (file)
@@ -490,7 +490,7 @@ class TypeDecorator(TypeEngine):
         tt.impl = typedesc
         return tt
 
-    @util.memoized_property
+    @property
     def _type_affinity(self):
         return self.impl._type_affinity
 
index efad45501f734f7f6e97bb83ba7c6f80588604a3..57193a397317486304a078f3f4cf9790cad1b522 100644 (file)
@@ -199,6 +199,23 @@ class TypeAffinityTest(fixtures.TestBase):
         ]:
             eq_(t1._compare_type_affinity(t2), comp, "%s %s" % (t1, t2))
 
+    def test_decorator_doesnt_cache(self):
+        from sqlalchemy.dialects import postgresql
+
+        class MyType(TypeDecorator):
+            impl = CHAR
+
+            def load_dialect_impl(self, dialect):
+                if dialect.name == 'postgresql':
+                    return dialect.type_descriptor(postgresql.UUID())
+                else:
+                    return dialect.type_descriptor(CHAR(32))
+
+        t1 = MyType()
+        d = postgresql.dialect()
+        assert t1._type_affinity is String
+        assert t1.dialect_impl(d)._type_affinity is postgresql.UUID
+
 class PickleMetadataTest(fixtures.TestBase):
     def testmeta(self):
         for loads, dumps in picklers():