MySQLdb1
MySQLdb1 copied to clipboard
MySQL errors don't line up with MySQLDB exceptions
I noticed today that OperationalError is thrown on a bunch of MySQL errors which should not be OperationalErrors. For example Error: 1054 SQLSTATE: 42S22 (ER_BAD_FIELD_ERROR) throws an OperationalError when it should throw ProgrammingError. The issue is that OperationalError is very useful if you want to programmatically detect actual connection issues. Having it thrown on a syntax related issue makes this task much harder.
One option would be to choose a different fallback exception. OperationalError, according to the documentation, should be thrown on issues related to MySQL's operation. For example: too many connections, bad handshake, etc. It may be safer to choose the generic "DatabaseError" as the fallback since that would be more accurate for the majority of the missing exceptions.
Another option is to categorize the rest of the MySQL errors and throw the correct exception for them all. Obviously this is a lot of work, but it would benefit the community a ton. Let me know if this is the path you want to take and I would be happy to help out.
Thanks!
moist handles MySQL error to Python exception mapping very differently: It's moved out of the C module and done entirely in Python. This doesn't particularly fix your problem outright, but it does make it easier to understand and make changes.
Basically, I have to figure out how to merge some of the architectural changes from moist back into MySQLdb, which is complicated by the fact that _mysql.c is split into multiple files in moist.
Ah, thats really good to know. Approx how stable is moist at this point? Would you recommend using the c library from moist over _mysql?
It's not a drop in replacement, because of the exception mapping and type conversion changes. But I think moist passes tests at this point. I just need to make some time to merge it back into MySQLdb.
Awesome! I need to take another look at it.
Also, any plans on reducing the version of setuptools required? I have installed it a couple times recently on older systems and having to update setuptools can be a bit janky. Plus I have also ran into an issue installing MySQLdb on machines without an internet connection, so the setuptools download that is attempted usually fails the install.
I realize that this isn't a huge value add for lots of people, but considering MySQLdb is easily the premier library for mysql connections in python, having a lower dependency footprint would be very much appreciated!
I'll see what I can do, but what python versions do you need? It may be time to drop Python 2.5 support (but not compatibility). It seems Travis-CI no longer has 2.5 available, despite the docs.
Python 2.6 and above. And preferably support distribute 0.6 and above or so. Here is an example of the experience on Centos 6.4 right now:
bash-4.1# easy_install --version
distribute 0.6.10
bash-4.1# python --version
Python 2.6.6
bash-4.1# easy_install MySQL-python
Searching for MySQL-python
Reading http://pypi.python.org/simple/MySQL-python/
Best match: MySQL-python 1.2.4
Downloading https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.4.zip#md5=ddf2386daf10a97af115ffad2ed4a9a0
Processing MySQL-python-1.2.4.zip
Running MySQL-python-1.2.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-md9ujf/MySQL-python-1.2.4/egg-dist-tmp-tAfthC
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.10 (/usr/lib/python2.6/site-packages))
error: Setup script exited with 2
bash-4.1# easy_install -U distribute
Searching for distribute
Reading http://pypi.python.org/simple/distribute/
Best match: distribute 0.7.3
Downloading https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip#md5=c6c59594a7b180af57af8a0cc0cf5b4a
Processing distribute-0.7.3.zip
Running distribute-0.7.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-u8yFk_/distribute-0.7.3/egg-dist-tmp-S4ohS1
warning: install_lib: 'build/lib' does not exist -- no Python modules to install
Adding distribute 0.7.3 to easy-install.pth file
Installed /usr/lib/python2.6/site-packages/distribute-0.7.3-py2.6.egg
Processing dependencies for distribute
Searching for setuptools>=0.7
Reading http://pypi.python.org/simple/setuptools/
Reading http://peak.telecommunity.com/snapshots/
Reading https://pypi.python.org/pypi/setuptools
Best match: setuptools 1.4
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.tar.gz#md5=5710464bc5a61d75f5087f15ce63cfe0
Processing setuptools-1.4.tar.gz
Running setuptools-1.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-UI2aOn/setuptools-1.4/egg-dist-tmp-De1o7p
Adding setuptools 1.4 to easy-install.pth file
Installing easy_install script to /usr/bin
Installing easy_install-2.6 script to /usr/bin
Installed /usr/lib/python2.6/site-packages/setuptools-1.4-py2.6.egg
Finished processing dependencies for distribute
bash-4.1# easy_install MySQL-python
Traceback (most recent call last):
File "/usr/bin/easy_install", line 9, in <module>
load_entry_point('distribute', 'console_scripts', 'easy_install')()
File "/usr/lib/python2.6/site-packages/setuptools-1.4-py2.6.egg/pkg_resources.py", line 357, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.6/site-packages/setuptools-1.4-py2.6.egg/pkg_resources.py", line 2393, in load_entry_point
raise ImportError("Entry point %r not found" % ((group,name),))
ImportError: Entry point ('console_scripts', 'easy_install') not found