Opened 10 years ago

Closed 10 years ago

#23031 closed Bug (invalid)

Django 1.7.x test failing for application with migrations and initial data

Reported by: linovia Owned by: nobody
Component: Migrations Version: 1.7-rc-1
Severity: Normal Keywords:
Cc: linovia Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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$ 

Change History (6)

comment:1 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted

Note that initial data isn't supported if an application has migrations. It may be worth throwing a more informative error message though.

comment:2 by linovia, 10 years ago

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.

comment:3 by Tim Graham, 10 years ago

Yes, it's a backwards incompatible change if an application uses migrations. It's also mentioned in the 1.7 release notes.

Last edited 10 years ago by Tim Graham (previous) (diff)

comment:4 by linovia, 10 years ago

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.

comment:5 by Tim Graham, 10 years ago

Yes, that sounds correct to me.

comment:6 by linovia, 10 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top