Opened 17 years ago
Closed 16 years ago
#5531 closed (fixed)
properly report when the mysqldb python package doesn't meet the version requirements
Reported by: | anonymous | Owned by: | Ramiro Morales |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | mysql | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I got this error:
Traceback (most recent call last): File "low_level_test1.cgi", line 84, in ? from django.test.utils import setup_test_environment File "./django/test/__init__.py", line 6, in ? from django.test.testcases import TestCase File "./django/test/testcases.py", line 6, in ? from django.db import transaction File "./django/db/__init__.py", line 23, in ? backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, ['']) ImportError: No module named mysql.base
But this is not the true error. The real problem is the version checking routines here: http://code.djangoproject.com/browser/django/trunk/django/db/backends/mysql/base.py#L13
Is raises a ImportError, too!
So i don't see message "MySQLdb-1.2.1p2 or newer is required; you have..." i see the wrong error messages from above: "No module named mysql.base"
Solution: I think the Version Exception must be a different class and not the generetic ImportError.
Attachments (1)
Change History (16)
comment:1 by , 17 years ago
follow-up: 6 comment:2 by , 17 years ago
Can you try changing the exception thwon on line 20 from ImportError
to ImproperlyConfigured
applying this mini-patch?:
-
django/db/backends/mysql/base.py
diff -r 32a3fe78cb9b django/db/backends/mysql/base.py
a b version = Database.version_info 17 17 version = Database.version_info 18 18 if (version < (1,2,1) or (version[:3] == (1, 2, 1) and 19 19 (len(version) < 5 or version[3] != 'final' or version[4] < 2))): 20 raise ImportError("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__) 20 from django.core.exceptions import ImproperlyConfigured 21 raise ImproperlyConfigured("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__) 21 22 22 23 from MySQLdb.converters import conversions 23 24 from MySQLdb.constants import FIELD_TYPE
(and yes, anything older than MySQLdb 1.2.1p1 won't work:
http://www.djangoproject.com/documentation/databases/#mysqldb
http://code.djangoproject.com/changeset/4751
Upgrade to a non-gamma version of MySQLdb)
comment:3 by , 17 years ago
Has patch: | set |
---|---|
Summary: | ImportError: No module named mysql.base → properly report when the mysqldb python package doesn't meet the version requirements |
Triage Stage: | Unreviewed → Ready for checkin |
tested, works as expected.
comment:4 by , 17 years ago
Has patch: | unset |
---|---|
Resolution: | → invalid |
Status: | new → closed |
The OP didn't see the version import error, he really doesn't have a mysql db module.
comment:5 by , 17 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
The OP is reporting that raising ImportError
is confusing because it generates a misleading
"import error no module mysql.base
" insted of reporting the unmet MysQLDb version requeriment.
Here I have a valid environment (ok, actually without a mysql server :) created by startproject/startapp
and I'm algo getting "ImportError: No module named mysql.base
" when simulating the reported scenario and running manage.py syncdb
Reopening the ticket and posting the proposed fix as a patch (it changes the error report to "django.core.exceptions.ImproperlyConfigured: MySQLdb-1.2.1p2 or newer is required; you have x.x.x
").
comment:6 by , 17 years ago
Replying to ramiro:
- raise ImportError("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__) + from django.core.exceptions import ImproperlyConfigured + raise ImproperlyConfigured("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__)
Hm. Use ImproperlyConfigured should be a good solution, i think.
(Btw. Attachment t5531.diff not found)
comment:7 by , 17 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
Please don't anonymously mark things ready for checkin.
by , 17 years ago
Attachment: | t5531.diff added |
---|
Reuploading the same patch file because the Trac attachments missing problem after the django server move
comment:8 by , 17 years ago
Has patch: | set |
---|
comment:9 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:10 by , 17 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
works as expected. Tested here.
comment:11 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:12 by , 16 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
django SVN r8449. Created a project and set project's settings.py's DATABASE_ENGINE to mysql and set all other options. Running "python manage.py syncdb" causes error "ImportError: No module named mysql.base". Mac OS X Leopard Server 10.5.4. Python 2.5.1.
comment:13 by , 16 years ago
Has patch: | unset |
---|---|
Triage Stage: | Ready for checkin → Unreviewed |
Is MySQLdb installed? Which version? Can you "import MySQLdb"?
comment:14 by , 16 years ago
rtdevmini:~ admin$ python
Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
comment:15 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
In that case, your problem has nothing to do with this bug, which was about checking the version when !MySQL was available and that was addressed in the above commit. You have a configuration problem. The django-users mailing list will be a better place to get help with that problem.
Note: I have MySQLdb v1.2.1g2 and not v1.2.1p2. Is there a different?