diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-02-02 13:00:19 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-02-02 15:04:46 -0500 |
commit | df55695f8e99f0523795a7b9e9cb9babee2e00e1 (patch) | |
tree | 011e27e6a74f60421030b2ef29dcb960e5220278 /lib/sqlalchemy/dialects/mysql/enumerated.py | |
parent | 5401c4d8514aa42e8ac4b5579454e68151e78a93 (diff) | |
download | sqlalchemy-df55695f8e99f0523795a7b9e9cb9babee2e00e1.tar.gz |
- add changelog and migration notes for new Enum features,
fixes #3095, #3292
- reorganize enum constructor to again work with the MySQL
ENUM type
- add a new create_constraint flag to Enum to complement that of
Boolean
- reinstate the CHECK constraint tests for enum, these already
fail /skip against the MySQL backend
- simplify lookup rules in Enum, have them apply to all varieties
of Enum equally
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/enumerated.py')
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/enumerated.py | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/enumerated.py b/lib/sqlalchemy/dialects/mysql/enumerated.py index 5c4dc61f0..567e95288 100644 --- a/lib/sqlalchemy/dialects/mysql/enumerated.py +++ b/lib/sqlalchemy/dialects/mysql/enumerated.py @@ -69,13 +69,16 @@ class ENUM(sqltypes.Enum, _EnumeratedValues): :param enums: The range of valid values for this ENUM. Values will be quoted when generating the schema according to the quoting flag (see - below). + below). This object may also be a PEP-435-compliant enumerated + type. - :param strict: Defaults to False: ensure that a given value is in this - ENUM's range of permissible values when inserting or updating rows. - Note that MySQL will not raise a fatal error if you attempt to store - an out of range value- an alternate value will be stored instead. - (See MySQL ENUM documentation.) + .. versionadded: 1.1 added support for PEP-435-compliant enumerated + types. + + :param strict: This flag has no effect. + + .. versionchanged:: The MySQL ENUM type as well as the base Enum + type now validates all Python data values. :param charset: Optional, a column-level character set for this string value. Takes precedence to 'ascii' or 'unicode' short-hand. @@ -109,8 +112,9 @@ class ENUM(sqltypes.Enum, _EnumeratedValues): literals for you. This is a transitional option. """ - values, length = self._init_values(enums, kw) - self.strict = kw.pop('strict', False) + + kw.pop('strict', None) + sqltypes.Enum.__init__(self, *enums) kw.pop('metadata', None) kw.pop('schema', None) kw.pop('name', None) @@ -118,29 +122,17 @@ class ENUM(sqltypes.Enum, _EnumeratedValues): kw.pop('native_enum', None) kw.pop('inherit_schema', None) kw.pop('_create_events', None) - _StringType.__init__(self, length=length, **kw) - sqltypes.Enum.__init__(self, *values) + _StringType.__init__(self, length=self.length, **kw) + + def _setup_for_values(self, values, objects, kw): + values, length = self._init_values(values, kw) + return sqltypes.Enum._setup_for_values(self, values, objects, kw) def __repr__(self): return util.generic_repr( self, to_inspect=[ENUM, _StringType, sqltypes.Enum]) - def bind_processor(self, dialect): - super_convert = super(ENUM, self).bind_processor(dialect) - - def process(value): - if self.strict and value is not None and value not in self.enums: - raise exc.InvalidRequestError('"%s" not a valid value for ' - 'this enum' % value) - if super_convert: - return super_convert(value) - else: - return value - return process - def adapt(self, cls, **kw): - if issubclass(cls, ENUM): - kw['strict'] = self.strict return sqltypes.Enum.adapt(self, cls, **kw) |