[Sqlalchemy-tickets] Issue #3841: Enum validation causes problems with values not in Enum (zzzeek/s
Brought to you by:
zzzeek
From: Christian <iss...@bi...> - 2016-10-28 17:34:26
|
New issue 3841: Enum validation causes problems with values not in Enum https://bitbucket.org/zzzeek/sqlalchemy/issues/3841/enum-validation-causes-problems-with Christian: After upgrading from 1.0 to 1.1.3, i get this error: ``` File "/home/xxx/.venv/xxx/lib/python2.7/site-packages/sqlalchemy/sql/sqltypes.py", line 1317, in _object_value_for_elem '"%s" is not among the defined enum values' % elem) LookupError: "" is not among the defined enum values ``` MySQL allows to insert data, that is not in the Enum. Test Case ``` #!python import unittest from sqlalchemy import (Column, Integer, Enum) from sqlalchemy.ext.declarative import declarative_base from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = ("mysql://root:develop@localhost/test123") db = SQLAlchemy(app) Base = declarative_base() class Test(db.Model): __tablename__ = 'test' id = Column(Integer, primary_key=True, nullable=False) default = Column(Enum('VALUE1','VALUE2')) db.drop_all() db.create_all() class TestSelfEnum(unittest.TestCase): def test_enum(self): db.session.add(Test(default="VALUE1")) db.engine.execute('INSERT INTO test(`default`) VALUES("")') db.session.commit() result = db.session.query(Test).all() ``` |