]> 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:08:42 +0000 (16:08 -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

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/sql/type_api.py
test/sql/test_operators.py

index 187bc2138cb507677533de5d7ecc49415fc6f1d2..4b036272bb59cdbfaa2c93bbcb0c326bc2371cbd 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 48b447b37014d868df1b1163d8974c7676666fac..444366bc08ead37d5822deacfc44af5a0c78d966 100644 (file)
@@ -631,8 +631,8 @@ class TypeDecorator(TypeEngine):
     @property
     def comparator_factory(self):
         return type("TDComparator",
-                    (TypeDecorator.Comparator, self.impl.comparator_factory),
-                    {})
+                (TypeDecorator.Comparator, self.impl.comparator_factory),
+                {})
 
     def _gen_dialect_impl(self, dialect):
         """
@@ -1026,6 +1026,11 @@ 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 _reconstitute_comparator(expression):
     return expression.comparator
 
index 1006dc33ab5dfa49d01e2c8c26f43df89855f7bb..9b6b2297f27e9bed4014cf1085730346dac94a56 100644 (file)
@@ -355,7 +355,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
 
@@ -368,6 +368,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):