Opened 13 years ago

Closed 13 years ago

#16613 closed Bug (fixed)

manage.py test fails on database creation (MySQL)

Reported by: Stan <stanislas.guerra@…> Owned by: nobody
Component: Uncategorized Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi,

Running python manage.py test with Django-trunk/Debian-Lenny/Python2.5/MySQL-5.0 give me this :

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/home/pages/lib/python/django/core/management/__init__.py", line 442, in execute_manager
    utility.execute()
  File "/home/pages/lib/python/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/pages/lib/python/django/core/management/commands/test.py", line 34, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/pages/lib/python/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/pages/lib/python/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/pages/lib/python/django/core/management/commands/test.py", line 54, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/pages/lib/python/django/test/simple.py", line 354, in run_tests
    old_config = self.setup_databases()
  File "/home/pages/lib/python/django/test/simple.py", line 291, in setup_databases
    test_db_name = connection.creation.create_test_db(self.verbosity, autoclobber=not self.interactive)
  File "/home/pages/lib/python/django/db/backends/creation.py", line 230, in create_test_db
    self.connection.features.confirm()
  File "/home/pages/lib/python/django/db/backends/__init__.py", line 382, in confirm
    self.can_introspect_foreign_keys = self._can_introspect_foreign_keys()
  File "/home/pages/lib/python/django/db/backends/mysql/base.py", line 146, in _can_introspect_foreign_keys
    cursor.execute('SHOW TABLE STATUS WHERE Name="INTROSPECT_TEST"')
  File "/home/pages/lib/python/django/db/backends/mysql/base.py", line 86, in execute
    return self.cursor.execute(query, args)
  File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1054, "Unknown column 'INTROSPECT_TEST' in 'where clause'")

I just swapped the quote line 146 and everything works fine.

Attachments (1)

db_backend_mysql_base.patch (703 bytes ) - added by Stan <stan__at__slashdev.me> 13 years ago.
Patch correcting the database of test for MySQL.

Download all attachments as: .zip

Change History (4)

by Stan <stan__at__slashdev.me>, 13 years ago

Attachment: db_backend_mysql_base.patch added

Patch correcting the database of test for MySQL.

comment:1 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted

From http://dev.mysql.com/doc/refman/5.1/en/string-syntax.html:

If the ANSI_QUOTES SQL mode is enabled, string literals can be quoted only within single quotation marks because a string quoted within double quotation marks is interpreted as an identifier.

I didn't find any other instances of this problem in django.db.backends.mysql.

I'm not sure if this needs tests. This is the only thing that prevents me from marking the ticket as RFC.

comment:2 by Aymeric Augustin, 13 years ago

Additional proof:

mysql> set sql_mode = 'ansi';
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW TABLE STATUS WHERE Name="INTROSPECT_TEST";
ERROR 1054 (42S22): Unknown column 'INTROSPECT_TEST' in 'where clause'

mysql> SHOW TABLE STATUS WHERE Name='INTROSPECT_TEST';
Empty set (0.00 sec)

comment:3 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [16613]:

Fixed #16613 -- Fixed test for introspected foreign keys in the MySQL backend if ANSI_QUOTES SQL mode is enabled. Thanks, Stan.

Note: See TracTickets for help on using tickets.
Back to Top