New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pony fails with mysql on Python 2.6 #87
Comments
Could you try to launch python2.6 and then do the import:
If the import fails then you need to check what is wrong with MySQLdb installation |
Nothing is wrong. Breakage was introduced with 0.5.4. |
Trying to figure out where is the problem. Could you launch python2.6 in your testing environment and do the import
What is the result of such import? |
Thanks for not supporting Centos 6 / RedHATE 6. These distros should die with very outdated Python 2.6. |
Hi! I found the cause of the problem, now we just have to figure out how to properly fix it. This has nothing to do with Python 2.6, this problem exists in all Python versions and all Pony versions starting from 0.5.4. In my code I use from pymysql import install_as_MySQLdb
install_as_MySQLdb() which I believe is a perfectly valid way to use pymysql instead of mysqldb. Now, the thing is that in Pony you have the following inside try:
import MySQLdb as mysql_module
except ImportError as e:
try:
import pymysql as mysql_module
except ImportError:
raise ImportError('No module named MySQLdb or pymysql found')
else:
import pymysql.converters as mysql_converters
from pymysql.constants import FIELD_TYPE, FLAG, CLIENT
mysql_converters.encoders[buffer] = lambda val: mysql_converters.escape_str(str(val))
mysql_converters.encoders[timedelta] = lambda val: mysql_converters.escape_str(timedelta2str(val))
mysql_module_name = 'pymysql'
else:
import MySQLdb.converters as mysql_converters
from MySQLdb.constants import FIELD_TYPE, FLAG, CLIENT
mysql_module_name = 'MySQLdb'
from _mysql import string_literal What happens here is that because I already installed pymysql as mysqldb using the To fix this we can eliminate the else block and move all it's code to the try block like this: try:
import MySQLdb as mysql_module
import MySQLdb.converters as mysql_converters
from MySQLdb.constants import FIELD_TYPE, FLAG, CLIENT
mysql_module_name = 'MySQLdb'
from _mysql import string_literal
except ImportError as e:
try:
import pymysql as mysql_module
except ImportError:
raise ImportError('No module named MySQLdb or pymysql found')
else:
import pymysql.converters as mysql_converters
from pymysql.constants import FIELD_TYPE, FLAG, CLIENT
mysql_converters.encoders[buffer] = lambda val: mysql_converters.escape_str(str(val))
mysql_converters.encoders[timedelta] = lambda val: mysql_converters.escape_str(timedelta2str(val))
mysql_module_name = 'pymysql' That will fix the error and make everybody happy. If you agree I can make a pull request or you can inject this fix by yourself. What do you think ? |
Thanks for the patch! I fixed the Pony code according to your suggestion, it will be part of the upcoming release PonyORM 0.6.2 |
Awesome, thanks! |
The documentation was moved from this repo to a separate one at https://github.com/ponyorm/pony-doc The compiled version can be found at https://docs.ponyorm.com # New features * Python 3.5 support * #132, #145: raw_sql() function was added * #126: Ability to use @db_session with generator functions * #116: Add support to select by UUID * Ability to get string SQL statement using the Query.get_sql() method * New function delete(gen) and Query.delete(bulk=False) * Now it is possible to override Entity.__init__() and declare custom entity methods # Backward incompatible changes * Normalizing table names for symmetric relationships * Autostrip - automatically remove leading and trailing characters # Bugfixes * #87: Pony fails with pymysql installed as MySQLdb * #118: Pony should reconnect if previous connection was created before process was forked * #121: Unable to update value of unique attribute * #122: AssertionError when changing part of a composite key * #127: a workaround for incorrect pysqlite locking behavior * #136: Cascade delete does not work correctly for one-to-one relationships * #141, #143: remove restriction on adding new methods to entities * #142: Entity.select_random() AssertionError * #147: Add 'atom_expr' symbol handling for Python 3.5 grammar
See this import error: https://travis-ci.org/maxtepkeev/architect/jobs/38495030
The text was updated successfully, but these errors were encountered: