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)

t5531.diff (763 bytes ) - added by Ramiro Morales 17 years ago.
Reuploading the same patch file because the Trac attachments missing problem after the django server move

Download all attachments as: .zip

Change History (16)

comment:1 by anonymous, 17 years ago

Note: I have MySQLdb v1.2.1g2 and not v1.2.1p2. Is there a different?

comment:2 by Ramiro Morales, 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  
    1717version = Database.version_info
    1818if (version < (1,2,1) or (version[:3] == (1, 2, 1) and
    1919        (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__)
    2122
    2223from MySQLdb.converters import conversions
    2324from 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 anonymous, 17 years ago

Has patch: set
Summary: ImportError: No module named mysql.baseproperly report when the mysqldb python package doesn't meet the version requirements
Triage Stage: UnreviewedReady for checkin

tested, works as expected.

comment:4 by Philippe Raoult, 17 years ago

Has patch: unset
Resolution: invalid
Status: newclosed

The OP didn't see the version import error, he really doesn't have a mysql db module.

comment:5 by Ramiro Morales, 17 years ago

Resolution: invalid
Status: closedreopened

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").

in reply to:  2 comment:6 by anonymous, 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 James Bennett, 17 years ago

Triage Stage: Ready for checkinAccepted

Please don't anonymously mark things ready for checkin.

by Ramiro Morales, 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 Ramiro Morales, 17 years ago

Has patch: set

comment:9 by Ramiro Morales, 17 years ago

Owner: changed from nobody to Ramiro Morales
Status: reopenednew

comment:10 by Philippe Raoult, 17 years ago

Triage Stage: AcceptedReady for checkin

works as expected. Tested here.

comment:11 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: newclosed

(In [7358]) Fixed #5531 -- Changes a while back meant we are handling import errors from
database backends differently now. Which meant the MySQLdb version check was
being swallowed. Changed the exception type to ensure this is percolated
correctly. Patch from Ramiro Morales.

comment:12 by pixelcort, 16 years ago

Resolution: fixed
Status: closedreopened

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 Michael Radziej, 16 years ago

Has patch: unset
Triage Stage: Ready for checkinUnreviewed

Is MySQLdb installed? Which version? Can you "import MySQLdb"?

comment:14 by pixelcort, 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 Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: reopenedclosed

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: See TracTickets for help on using tickets.
Back to Top