From a96267639a914a4ebfd8a5ee510d1b6e031818e7 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 27 Jun 2014 16:08:42 -0400 Subject: [PATCH] - Fixed a bug within the custom operator plus :meth:`.TypeEngine.with_variant` system, whereby using a :class:`.TypeDecorator` in conjunction with variant would fail with an MRO error when a comparison operator was used. fixes #3102 Conflicts: lib/sqlalchemy/sql/type_api.py --- doc/build/changelog/changelog_08.rst | 9 ++++++++ lib/sqlalchemy/types.py | 4 ++++ test/sql/test_operators.py | 31 +++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index a9922b768f..6c21a47aa0 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -11,6 +11,15 @@ .. changelog:: :version: 0.8.7 + .. change:: + :tags: bug, sql + :versions: 1.0.0, 0.9.7 + :tickets: 3102 + + Fixed a bug within the custom operator plus :meth:`.TypeEngine.with_variant` + system, whereby using a :class:`.TypeDecorator` in conjunction with + variant would fail with an MRO error when a comparison operator was used. + .. change:: :tags: bug, mysql :versions: 1.0.0, 0.9.7 diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index d2351e619b..b53d92632e 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -961,6 +961,10 @@ class Variant(TypeDecorator): mapping[dialect_name] = type_ return Variant(self.impl, mapping) + @property + def comparator_factory(self): + """express comparison behavior in terms of the base type""" + return self.impl.comparator_factory def to_instance(typeobj, *arg, **kw): if typeobj is None: diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index fd70c2d156..cdf200e621 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -314,7 +314,7 @@ class TypeDecoratorComparatorTest(_CustomComparatorTests, fixtures.TestBase): class MyInteger(TypeDecorator): impl = Integer - class comparator_factory(TypeEngine.Comparator): + class comparator_factory(TypeDecorator.Comparator): def __init__(self, expr): self.expr = expr @@ -324,6 +324,35 @@ class TypeDecoratorComparatorTest(_CustomComparatorTests, fixtures.TestBase): return MyInteger +class TypeDecoratorWVariantComparatorTest(_CustomComparatorTests, fixtures.TestBase): + def _add_override_factory(self): + + class SomeOtherInteger(Integer): + class comparator_factory(TypeEngine.Comparator): + def __init__(self, expr): + self.expr = expr + + def __add__(self, other): + return self.expr.op("not goofy")(other) + + def __and__(self, other): + return self.expr.op("not goofy_and")(other) + + class MyInteger(TypeDecorator): + impl = Integer + + class comparator_factory(TypeDecorator.Comparator): + def __init__(self, expr): + self.expr = expr + + def __add__(self, other): + return self.expr.op("goofy")(other) + + def __and__(self, other): + return self.expr.op("goofy_and")(other) + + return MyInteger().with_variant(SomeOtherInteger, "mysql") + class CustomEmbeddedinTypeDecoratorTest(_CustomComparatorTests, fixtures.TestBase): def _add_override_factory(self): -- 2.47.2