From: Mike Bayer Date: Thu, 10 Jul 2014 15:26:13 +0000 (-0400) Subject: - The :meth:`.TypeEngine.with_variant` method will now accept a X-Git-Tag: rel_1_0_0b1~336 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e5d0fa94937b6572bbf4a08d4a8870e749fcea03;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - The :meth:`.TypeEngine.with_variant` method will now accept a type class as an argument which is internally converted to an instance, using the same convention long established by other constructs such as :class:`.Column`. fixes #3122 --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index f6aa96a0f4..6473da10bd 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -14,6 +14,15 @@ :version: 0.9.7 :released: + .. change:: + :tags: bug, sql + :tickets: 3122 + + The :meth:`.TypeEngine.with_variant` method will now accept a + type class as an argument which is internally converted to an + instance, using the same convention long established by other + constructs such as :class:`.Column`. + .. change:: :tags: bug, orm :tickets: 3117 diff --git a/lib/sqlalchemy/sql/type_api.py b/lib/sqlalchemy/sql/type_api.py index 6fa0bc64a2..f9af21baac 100644 --- a/lib/sqlalchemy/sql/type_api.py +++ b/lib/sqlalchemy/sql/type_api.py @@ -263,7 +263,7 @@ class TypeEngine(Visitable): .. versionadded:: 0.7.2 """ - return Variant(self, {dialect_name: type_}) + return Variant(self, {dialect_name: to_instance(type_)}) @util.memoized_property diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 1130c9e40c..e5c1e7b624 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -816,6 +816,13 @@ class VariantTest(fixtures.TestBase, AssertsCompiledSQL): dialect=dialects.postgresql.dialect() ) + def test_to_instance(self): + self.assert_compile( + self.UTypeOne().with_variant(self.UTypeTwo, "postgresql"), + "UTYPETWO", + dialect=dialects.postgresql.dialect() + ) + def test_compile_composite(self): self.assert_compile( self.composite,