diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-06-27 16:08:42 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-06-27 16:08:42 -0400 |
commit | 01215cdaef4579b5d0806abd060a2dd90acabf9b (patch) | |
tree | 11fecd63452d91e8eae8c95c5e64a7db6b5e8102 | |
parent | 3d7cd1741b02d5c0e2ca08d7437759cda7c2a9be (diff) | |
download | sqlalchemy-01215cdaef4579b5d0806abd060a2dd90acabf9b.tar.gz |
- 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
-rw-r--r-- | doc/build/changelog/changelog_08.rst | 9 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/type_api.py | 9 | ||||
-rw-r--r-- | test/sql/test_operators.py | 31 |
3 files changed, 46 insertions, 3 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 187bc2138..4b036272b 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -12,6 +12,15 @@ :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 :tickets: 3101 diff --git a/lib/sqlalchemy/sql/type_api.py b/lib/sqlalchemy/sql/type_api.py index 48b447b37..444366bc0 100644 --- a/lib/sqlalchemy/sql/type_api.py +++ b/lib/sqlalchemy/sql/type_api.py @@ -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 diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index 1006dc33a..9b6b2297f 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -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): |