From 0b0764b62ba87bdec41d0fc86618f3779cb4e3f0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 20 Oct 2013 16:25:46 -0400 Subject: - add a type_coerce() step within Enum, Boolean to the CHECK constraint, so that the custom type isn't exposed to an operation that is against the "impl" type's constraint, [ticket:2842] - this change showed up as some recursion overflow in pickling with labels, add a __reduce__() there....pickling of expressions is less and less something that's very viable... --- lib/sqlalchemy/sql/elements.py | 3 +++ lib/sqlalchemy/sql/sqltypes.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 2688ef103..f70496418 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -1842,6 +1842,9 @@ class Label(ColumnElement): self._type = type_ self._proxies = [element] + def __reduce__(self): + return self.__class__, (self.name, self._element, self._type) + @util.memoized_property def _order_by_label_element(self): return self diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index db0ad248c..1d7dacb91 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -12,7 +12,7 @@ import datetime as dt import codecs from .type_api import TypeEngine, TypeDecorator, to_instance -from .elements import quoted_name +from .elements import quoted_name, type_coerce from .default_comparator import _DefaultColumnComparator from .. import exc, util, processors from .base import _bind_or_error, SchemaEventTarget @@ -1059,7 +1059,7 @@ class Enum(String, SchemaType): SchemaType._set_table(self, column, table) e = schema.CheckConstraint( - column.in_(self.enums), + type_coerce(column, self).in_(self.enums), name=self.name, _create_rule=util.portable_instancemethod( self._should_create_constraint) @@ -1196,7 +1196,7 @@ class Boolean(TypeEngine, SchemaType): return e = schema.CheckConstraint( - column.in_([0, 1]), + type_coerce(column, self).in_([0, 1]), name=self.name, _create_rule=util.portable_instancemethod( self._should_create_constraint) -- cgit v1.2.1