From: Mike Bayer Date: Mon, 28 Nov 2011 17:44:56 +0000 (-0500) Subject: - [bug] Fixed bug whereby TypeDecorator would X-Git-Tag: rel_0_7_4~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=beef2b5aa811efd42a111c87a4308d6584c78b97;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [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. --- diff --git a/CHANGES b/CHANGES index bb2266f0c8..f3793cfc33 100644 --- 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 diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index a4714d3d83..79799da8f3 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -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 diff --git a/test/sql/test_types.py b/test/sql/test_types.py index efad45501f..57193a3973 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -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():