#31398: multiple_database.tests.AuthTestCase doesn't flush the default database
if
transactions aren't supported.
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Hassaan
| Ali Wattoo
Type: Bug | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tim Graham):
Hi Hassaan, I can't reproduce the issue you described.
After adding:
{{{
'OPTIONS': {
'init_command': 'SET default_storage_engine=MYISAM',
}
}}}
to both databases in the test settings files, I can reproduce the issue I
reported:
{{{
$ ./tests/runtests.py --settings=test_mysql --parallel=1
multiple_database.tests.AuthTestCase
Testing against Django installed in '/home/tim/code/django/django'
Creating test database for alias 'default'...
Creating test database for alias 'other'...
System check identified no issues (0 silenced).
.E
======================================================================
ERROR: test_dumpdata (multiple_database.tests.AuthTestCase)
dumpdata honors allow_migrate restrictions on the router
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
_execute
return self.cursor.execute(sql, params)
File "/home/tim/code/django/django/db/backends/mysql/base.py", line 73,
in execute
return self.cursor.execute(query, args)
File "/home/tim/.virtualenvs/django37/lib/python3.7/site-
packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/home/tim/.virtualenvs/django37/lib/python3.7/site-
packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/home/tim/.virtualenvs/django37/lib/python3.7/site-
packages/MySQLdb/connections.py", line 239, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.IntegrityError: (1062, "Duplicate entry 'bob' for key
'username'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/tim/code/django/tests/multiple_database/tests.py", line
1564, in test_dumpdata
User.objects.db_manager('default').create_user('bob',
'[email protected]')
File "/home/tim/code/django/django/contrib/auth/models.py", line 146, in
create_user
return self._create_user(username, email, password, **extra_fields)
File "/home/tim/code/django/django/contrib/auth/models.py", line 140, in
_create_user
user.save(using=self._db)
File "/home/tim/code/django/django/contrib/auth/base_user.py", line 66,
in save
super().save(*args, **kwargs)
File "/home/tim/code/django/django/db/models/base.py", line 750, in save
force_update=force_update, update_fields=update_fields)
File "/home/tim/code/django/django/db/models/base.py", line 788, in
save_base
force_update, using, update_fields,
File "/home/tim/code/django/django/db/models/base.py", line 891, in
_save_table
results = self._do_insert(cls._base_manager, using, fields,
returning_fields, raw)
File "/home/tim/code/django/django/db/models/base.py", line 931, in
_do_insert
using=using, raw=raw,
File "/home/tim/code/django/django/db/models/manager.py", line 85, in
manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/tim/code/django/django/db/models/query.py", line 1248, in
_insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/home/tim/code/django/django/db/models/sql/compiler.py", line
1386, in execute_sql
cursor.execute(sql, params)
File "/home/tim/code/django/django/db/backends/utils.py", line 66, in
execute
return self._execute_with_wrappers(sql, params, many=False,
executor=self._execute)
File "/home/tim/code/django/django/db/backends/utils.py", line 75, in
_execute_with_wrappers
return executor(sql, params, many, context)
File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
_execute
return self.cursor.execute(sql, params)
File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
_execute
return self.cursor.execute(sql, params)
File "/home/tim/code/django/django/db/backends/mysql/base.py", line 73,
in execute
return self.cursor.execute(query, args)
File "/home/tim/.virtualenvs/django37/lib/python3.7/site-
packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/home/tim/.virtualenvs/django37/lib/python3.7/site-
packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/home/tim/.virtualenvs/django37/lib/python3.7/site-
packages/MySQLdb/connections.py", line 239, in query
_mysql.connection.query(self, query)
django.db.utils.IntegrityError: (1062, "Duplicate entry 'bob' for key
'username'")
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31398#comment:7>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.3ad91a7d32e60ae64ebd160ba4c6547a%40djangoproject.com.