[Django] #23031: Django 1.7.x test failing for application with migrations and initial data

6 views
Skip to first unread message

Django

unread,
Jul 15, 2014, 8:36:04 AM7/15/14
to django-...@googlegroups.com
#23031: Django 1.7.x test failing for application with migrations and initial data
----------------------------+----------------------
Reporter: linovia | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+----------------------
It seems commit 0dd737a719cfbd3bc11ff6f2b90161883fcebea0 introduced a
regression in the following case:
- the application has migrations
- the application has initial_data

With this configuration Django will crash before any test is run.
This is caused by the initial_data being loaded at the end of the flush
while the migrations did not create the associated tables yet:

{{{
(django17_test) air-de-xavier:demo xordoquy$ python manage.py test
Creating test database for alias 'default'...
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py", line
385, in execute_from_command_line
utility.execute()
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py", line
377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/commands/test.py",
line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/base.py", line 288,
in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/commands/test.py",
line 71, in execute
super(Command, self).execute(*args, **options)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/base.py", line 337,
in execute
output = self.handle(*args, **options)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/commands/test.py",
line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/test/runner.py", line 147, in
run_tests
old_config = self.setup_databases()
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/test/runner.py", line 109, in
setup_databases
return setup_databases(self.verbosity, self.interactive, **kwargs)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/test/runner.py", line 299, in
setup_databases
serialize=connection.settings_dict.get("TEST_SERIALIZE", True),
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/backends/creation.py", line 374,
in create_test_db
test_flush=True,
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py", line
115, in call_command
return klass.execute(*args, **defaults)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/base.py", line 337,
in execute
output = self.handle(*args, **options)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/commands/migrate.py",
line 141, in handle
inhibit_post_migrate=True,
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py", line
115, in call_command
return klass.execute(*args, **defaults)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/base.py", line 337,
in execute
output = self.handle(*args, **options)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/base.py", line 532,
in handle
return self.handle_noargs(**options)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/commands/flush.py",
line 85, in handle_noargs
call_command('loaddata', 'initial_data', **options)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py", line
115, in call_command
return klass.execute(*args, **defaults)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/base.py", line 337,
in execute
output = self.handle(*args, **options)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/commands/loaddata.py",
line 60, in handle
self.loaddata(fixture_labels)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/commands/loaddata.py",
line 90, in loaddata
self.load_label(fixture_label)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/management/commands/loaddata.py",
line 147, in load_label
obj.save(using=self.using)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/core/serializers/base.py", line
173, in save
models.Model.save_base(self.object, using=using, raw=True)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/models/base.py", line 618, in
save_base
updated = self._save_table(raw, cls, force_insert, force_update,
using, update_fields)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/models/base.py", line 680, in
_save_table
forced_update)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/models/base.py", line 724, in
_do_update
return filtered._update(values) > 0
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/models/query.py", line 598, in
_update
return query.get_compiler(self.db).execute_sql(CURSOR)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/models/sql/compiler.py", line
1003, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/models/sql/compiler.py", line
785, in execute_sql
cursor.execute(sql, params)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/backends/utils.py", line 65, in
execute
return self.cursor.execute(sql, params)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/backends/utils.py", line 65, in
execute
return self.cursor.execute(sql, params)
File "/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-
packages/Django-1.7c1-py2.7.egg/django/db/backends/sqlite3/base.py", line
485, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: Problem installing fixture
'/Users/xordoquy/django17_test/demo/demo/core/fixtures/initial_data.json':
Could not load core.Bug(pk=1): no such table: core_bug
(django17_test) air-de-xavier:demo xordoquy$
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23031>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 15, 2014, 8:45:08 AM7/15/14
to django-...@googlegroups.com
#23031: Django 1.7.x test failing for application with migrations and initial data
----------------------------+------------------------------------

Reporter: linovia | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
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
----------------------------+------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

Note that [https://docs.djangoproject.com/en/1.7/howto/initial-data
/#automatically-loading-initial-data-fixtures initial data isn't supported
if an application has migrations]. It may be worth throwing a more
informative error message though.

--
Ticket URL: <https://code.djangoproject.com/ticket/23031#comment:1>

Django

unread,
Jul 15, 2014, 9:32:51 AM7/15/14
to django-...@googlegroups.com
#23031: Django 1.7.x test failing for application with migrations and initial data
----------------------------+------------------------------------

Reporter: linovia | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
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 linovia):

I saw that but the documentation mentions it is deprecated, not
unsupported.
I intended to set the bug as a documentation one but that would break the
deprecation policy.

--
Ticket URL: <https://code.djangoproject.com/ticket/23031#comment:2>

Django

unread,
Jul 15, 2014, 9:59:38 AM7/15/14
to django-...@googlegroups.com
#23031: Django 1.7.x test failing for application with migrations and initial data
----------------------------+------------------------------------

Reporter: linovia | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
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 timo):

Yes, it a backwards incompatible change if an application uses migrations.
It's also mentioned in the
[https://docs.djangoproject.com/en/dev/releases/1.7/#schema-migrations 1.7
release notes].

--
Ticket URL: <https://code.djangoproject.com/ticket/23031#comment:3>

Django

unread,
Jul 15, 2014, 2:50:36 PM7/15/14
to django-...@googlegroups.com
#23031: Django 1.7.x test failing for application with migrations and initial data
----------------------------+------------------------------------

Reporter: linovia | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
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 linovia):

Thinking a bit more about this, I should probably close this bug and open
a new one stating that flush command should not install initial_data for
application that have migrations.
I created a dummy project (one app with a model and initial data) and
here's what flush gives:

{{{
(django17_test) air-de-xavier:demo xordoquy$ python manage.py flush
You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the
'/Users/xordoquy/django17_test/demo/db.sqlite3' database,
and return each table to an empty state.
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Installed 1 object(s) from 1 fixture(s)
}}}

If Django doesn't install initial_data for apps with migrations then we
have a bug in the flush command - which is called by the tests.

--
Ticket URL: <https://code.djangoproject.com/ticket/23031#comment:4>

Django

unread,
Jul 15, 2014, 3:52:00 PM7/15/14
to django-...@googlegroups.com
#23031: Django 1.7.x test failing for application with migrations and initial data
----------------------------+------------------------------------

Reporter: linovia | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
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 timo):

Yes, that sounds correct to me.

--
Ticket URL: <https://code.djangoproject.com/ticket/23031#comment:5>

Django

unread,
Jul 22, 2014, 10:59:33 AM7/22/14
to django-...@googlegroups.com
#23031: Django 1.7.x test failing for application with migrations and initial data
----------------------------+------------------------------------
Reporter: linovia | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7-rc-1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by linovia):

* status: new => closed
* resolution: => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/23031#comment:6>

Reply all
Reply to author
Forward
0 new messages