#15782: Runserver/runfcgi/startup with MySQL is unlike any other database
-----------------------+---------------------------------------------
Reporter: toofishes | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Database layer (models, ORM)
Version: 1.3 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 |
-----------------------+---------------------------------------------
Django provides a BaseDatabaseValidation class. The only database engine
to subclass this is MySQL.
To reproduce:
{{{
$ django-admin.py foobar
$ cd foobar
<edit settings.py to use ENGINE "django.db.backends.mysql">
$ python2 manage.py runserver
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run
of <django.contrib.staticfiles.management.commands.runserver.Command
object at 0x27f5950>>
Traceback (most recent call last):
File "/usr/lib/python2.7/site-
packages/django/core/management/commands/runserver.py", line 88, in
inner_run
self.validate(display_num_errors=True)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py",
line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/lib/python2.7/site-
packages/django/core/management/validation.py", line 103, in
get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/usr/lib/python2.7/site-
packages/django/db/backends/mysql/validation.py", line 14, in
validate_field
db_version = self.connection.get_server_version()
File "/usr/lib/python2.7/site-
packages/django/db/backends/mysql/base.py", line 338, in
get_server_version
self.cursor()
File "/usr/lib/python2.7/site-packages/django/db/backends/__init__.py",
line 250, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/lib/python2.7/site-
packages/django/db/backends/mysql/base.py", line 322, in _cursor
self.connection = Database.connect(**kwargs)
File "/usr/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in
Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/MySQLdb/connections.py", line
187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL
server through socket '/var/run/mysqld/mysqld.sock' (2)")
}}}
Expected result:
{{{
$ django-admin.py foobar
$ cd foobar
<edit settings.py to use ENGINE "django.db.backends.sqlite3">
$ python2 manage.py runserver
Validating models...
0 errors found
Django version 1.3, using settings 'foobar.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
}}}
Why this is a problem:
1. The number one reason this is bad- no other database engine completely
halts the Django project load if it is not up. It simply cannot service
requests at all. All other database engines at least show a helpful 500
page on each failed request.
2. Validation like this doesn't come early enough for someone that
develops on one database engine and then switches to MySQL.
3. The validation that needs a valid connection is testing an extreme edge
case- those using versions before 5.0.3. From http://www.mysql.com/support
/eol-notice.html, Extended Support for 4.1 and Active Support for 5.0
ended ended 2009-12-31.
4. We are likely missing validation cases for other databases; we should
be consistent in trying to do it right or not do it at all.
5. The validation here isn't even correct for unique fields. max_length
can be greater than 255, in reality the unique indexes are constrained to
1000 bytes. For that matter, this also does nothing to keep one from
shooting themselves in the foot with a combo unique index produced by
unique_together.
Potential fixes:
1. Drop this database field validation completely, as only one database is
even providing it and not even fully checking.
2. Remove the bits referencing the connection; this will solve the most
severe problem and those using old database versions should be well aware
of the restrictions.
3. Make the validation module do the right thing more often, fixing MySQL
and adding it for other databases.
I'd be happy to provide a patch for #1 or #2, but wanted some feedback
first.
Tangentially related to #7040.
--
Ticket URL: <http://code.djangoproject.com/ticket/15782>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.