]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed a bug within the custom operator plus :meth:`.TypeEngine.with_variant`
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 27 Jun 2014 20:08:42 +0000 (16:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 27 Jun 2014 20:11:56 +0000 (16:11 -0400)
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
lib/sqlalchemy/types.py
test/sql/test_operators.py

index a9922b768fdcc7a364225277238a5cd45c8c0934..6c21a47aa09842dec8e417ed2782c5b316dfb135 100644 (file)
 .. 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
index d2351e619be39d492333f191d20d5f76181ee207..b53d92632ecb9feb64e10f0d18e467526596322a 100644 (file)
@@ -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:
index fd70c2d156a42e272c4d2b057b70211685806aa7..cdf200e6216e00654471971d2d42cb7dd84fc5a0 100644 (file)
@@ -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):