julien-duponchelle / julien-duponchelle/python-mysql-replication
Enum columns with value of empty string show incorrect value
- Dominant language
- Python
- Stars
- 2.4k
- Forks
- 690
- PR merge metrics
- No merged PRs in 30d
Description
When a column in mysql is of type ENUM and a value other than one of the assigned enum values is inserted, mysql instead inserts this as an empty string. Currently when one of these empty strings comes through the binary log reader, it incorrectly assigns one of the valid enum values.
Example:
```
create table test_enums (
uid int(11) primary key auto_increment,
enum_column enum('e1', 'e2')
) engine=innodb default charset=utf8;
insert into test_enums (enum_column) values ('invalid');
select * from test_enums;
uid: 1
enum_column:
```
Now when we dump this very event from the binary log reader, we get:
```
Values:
--
('*', u'uid', ':', 1)
('*', u'enum_column', ':', u'e2')
()
```
I would fork and fix this issue, as a matter of fact I tried. But I'm not a python developer and I had issues working with dependencies when trying to fix this locally (I'm really, really, not a python developer).
My thoughts on a fix would be to change column.py lines 74-76 to something like:
```
if self.type == FIELD_TYPE.ENUM:
self.enum_values = enums.replace('enum(', '')\
.replace(')', '').replace('\'', '').split(',')
if len(self.enum_values) > 0:
self.enum_values.append('')
```
Since I couldn't test this locally, I am not sure it will fix the issue.
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.