Bug #73455 abuse of "import *" in mysql-connector-python messes up exception handling
Submitted: 2 Aug 2014 16:16 Modified: 4 Nov 2014 8:17
Reporter: Håken Lid Email Updates:
Status: Closed Impact on me:
Category:Connector / Python Severity:S2 (Serious)
Version:1.2.2 OS:Linux
Assigned to: CPU Architecture:Any
Tags: django1.7 python3.4

[2 Aug 2014 16:16] Håken Lid
Using Django==1.7, python==3.4 and mysql-connector-python==1.2.2

Cause of error found in:
mysql/connector/django/base.py line 44 and 45

44 from django.db import utils
45 from django.db.backends import *

importing * in line 45 overwrites the previously imported django.db.utils with django.db.backends.utils

This messes up later exception handling since utils.IntegrityError does not exist any more.

How to repeat:
Raise a database exception that is caught in CursorWrapper._execute_wrapper() and I get this error instead of the expected useful error message.

Exception Type:	AttributeError
Exception Value: 'module' object has no attribute 'IntegrityError'

Suggested fix:
Best fix:
Don't use import *

Not best fix:
change ordering of imports. Swapping line 45 and 44 seems to work.
[5 Aug 2014 8:40] Peeyush Gupta
Thank you for the bug report.

This issue will be resolved in the upcoming release.
[4 Nov 2014 8:17] Peeyush Gupta
Fixed in v1.2.3.