diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-10-28 14:13:31 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-10-28 14:17:40 -0400 |
commit | dd4e09d38729c2479af19da082a07f0c44f7026c (patch) | |
tree | 49aa2cef401d89ca448778aaad1a7922cc000891 /test | |
parent | 60b68ff4ee15ad1be42031f90156072cdfe1f1d0 (diff) | |
download | sqlalchemy-dd4e09d38729c2479af19da082a07f0c44f7026c.tar.gz |
Add check for blank string coming from MySQL's enum
MySQL's native ENUM type supports any non-valid value being sent, and
in response will return a blank string. A hardcoded rule to check for
"is returning the blank string" has been added to the MySQL
implementation for ENUM so that this blank string is returned to the
application rather than being rejected as a non-valid value. Note that
if your MySQL enum is linking values to objects, you still get the
blank string back.
Change-Id: I61f85c20293a48b0c11a31f2a19f6756c206bd20
Fixes: #3841
Diffstat (limited to 'test')
-rw-r--r-- | test/dialect/mysql/test_types.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/dialect/mysql/test_types.py b/test/dialect/mysql/test_types.py index 0cbb507c5..48663da25 100644 --- a/test/dialect/mysql/test_types.py +++ b/test/dialect/mysql/test_types.py @@ -1063,6 +1063,30 @@ class EnumSetTest( eq_(t.c.e6.type.values, ("", "a")) eq_(t.c.e7.type.values, ("", "'a'", "b'b", "'")) + @testing.provide_metadata + def test_broken_enum_returns_blanks(self): + t = Table( + 'enum_missing', + self.metadata, + Column('id', Integer, primary_key=True), + Column('e1', sqltypes.Enum('one', 'two', 'three')), + Column('e2', mysql.ENUM('one', 'two', 'three')) + ) + t.create() + + with testing.db.connect() as conn: + conn.execute(t.insert(), {"e1": "nonexistent", "e2": "nonexistent"}) + conn.execute(t.insert(), {"e1": "", "e2": ""}) + conn.execute(t.insert(), {"e1": "two", "e2": "two"}) + conn.execute(t.insert(), {"e1": None, "e2": None}) + + eq_( + conn.execute( + select([t.c.e1, t.c.e2]).order_by(t.c.id) + ).fetchall(), + [("", ""), ("", ""), ("two", "two"), (None, None)] + ) + def colspec(c): return testing.db.dialect.ddl_compiler( |