Re: [Sqlalchemy-tickets] [sqlalchemy] #2917: support "down" adaptions? (was: sqlalchemy.dialects.my
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2014-01-22 19:28:42
|
#2917: support "down" adaptions? (was: sqlalchemy.dialects.mysql.base.ENUM is not
adaptable to sqlalchemy.sql.sqltypes.Enum)
----------------------------------+------------------------------------
Reporter: jpcalderone | Owner:
Type: defect | Status: new
Priority: medium | Milestone:
Component: mysql | Severity: no triage selected yet
Resolution: | Keywords:
Progress State: awaiting triage |
----------------------------------+------------------------------------
Comment (by zzzeek):
`strict` is not ignored, it is used by `mysql.ENUM.bind_processor`. It's
tested in mysql.test_types:EnumSetTest.test_enum which fails if you
comment that line out, as currently the ENUM is adapted to a new object
with the same type.
The issue here is related to what I would characterize as unintended use
of the `adapt()` method - this method is until now only intended for "up"
adaptions, that is from a more generic type to a dialect-specific type,
and not for a "down" adaption from a specific type to a more general.
That use case doesn't exist within SQLAlchemy internals.
What's special about "strict" here as opposed to all the other custom
keyword arguments that other MySQL types and other types from other
dialects include, is that it is dialect-specific but also affects the
runtime type-coercion behavior. That's why this special adapt() method
exists - because adapt() is already only used to produce a new type object
that's appropriate for run-time type coercion.
in the vast majority of cases elsewhere I've just looked at, types have
predictable argument signatures because all keyword arguments are
ultimately explicitly within the `__init__` method of the type itself or a
superclass; the default adapt() method looks at `__bases__` to get at
these additional arguments. `Enum` is special because it starts out with
`*varargs`, and Python 2 doesn't provide Py3K's nice "keyword-only
arguments" feature that we'd otherwise be using here.
We have a suite that tests all possible legal "up" adaptions but not
"down" adaptions. That would need to be added. Autocode should be able
to fix this right now just by using the adapt() of the general type:
{{{
Enum.adapt(meta.tables['foo'].columns['bar'].type, Enum)
}}}
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2917#comment:1>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|