ARRAY of ENUM doesn't do any validation
SQLAlchemy is not complaining when I have a model with
array_enum = Column(ARRAY(Enum(*LIST_OF_ENUM, native_enum=False)))
but doens't seem to do any validation and I have been able to insert value outside the enum in the array.
Comments (11)
-
repo owner -
reporter I was expecting the insert to fail, it seems like no CHECK constraint was added on the array content. To be honest, I don't know if this allowed.
I initially tried native ENUM but the schema creation fail:
sqlalchemy.exc.CompileError: Postgresql ENUM type requires a name.
I just tried "python_validation=True" but this raise and error:
TypeError: __init__() got an unexpected keyword argument 'python_validation'
I also cannot see it in the doc : http://docs.sqlalchemy.org/en/latest/core/types.html#sqlalchemy.types.Enum Is it in something recent.
I will try to add a
@validate
to check the item inserted in the ARRAY , not a big deal that ENUM didn't work but as it didn't complain then I though it will be working. -
repo owner I just tried "python_validation=True" but this raise and error:
I am suggesting this as a potential new feature.
Right now, ENUM creates a CHAR() plus a CHECK constraint for the values in that CHAR. I don't know how this could be acheived inside of a Postgresql ARRAY.
-
reporter Sorry I misunderstood. It could be useful to have Enum with python validation as it often a pain to migrate. Thanks for your answers.
-
repo owner the work here is:
-
add flag
python_validation=True
to sqltypes.Enum -
add a bind processor that takes effect when this flag is enabled
-
document the flag in the docstring
-
add tests to test/sql/test_types.py
-
changelog message in changelog_XX , depending on which version we're at
-
-
repo owner -
assigned issue to
-
assigned issue to
-
repo owner - changed milestone to 1.0.xx
-
repo owner - changed milestone to 1.x.xx
-
repo owner see https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/72/support-native-enum/diff where we might just add validation in all cases for 1.1
-
repo owner - changed status to resolved
- 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
→ <<cset df55695f8e99>>
-
repo owner regression: a SQL expression that concatenates to the ENUM maintains the type ENUM which then fails because the value isn't in the list. totally not-tested use case.
- Log in to comment
we use a CHECK constraint for ENUM. I have no idea what you'd want here, except in-Python validation? I'd call this a feature then? add a flag "python_validation=True" to ENUM, how's that? Since I can't imagine how a CHECK could do this?