Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#23077 closed Bug (invalid)

Django 1.7 rc1 flush command loads initial data regardless of the migrations

Reported by: linovia Owned by: Andrew Godwin
Component: Migrations Version: 1.7-rc-1
Severity: Release blocker Keywords:
Cc: xordoquy@…, Tim Graham Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is following ticket #23031

We have an issue with test runner that crashes on application that has both initial_data and migrations.
The reason is the database is flushed before the migration however, flush command will try to load initial_data anyway. This will crash the test runner.
Following the documentation, initial_data is deprecated, not yet forbidden at all.

Attachments (2)

23077.diff (1.5 KB) - added by merb 4 years ago.
new-23077.diff (470 bytes) - added by merb 4 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 4 years ago by Tim Graham

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:2 Changed 4 years ago by merb

That is somewhat funny.

I don't know if this is a good solution. But I wrote a patch for it. And attach it here.

Somehow migrated apps who has fixture were loaded, too.

I don't have any output yet since I didn't know if this is wished. Maybe a Note at the start of loaddata would be enough since its in the patchnotes anyway.

Oh and running against master works fine. (PY27, PY34)

Last edited 4 years ago by merb (previous) (diff)

Changed 4 years ago by merb

Attachment: 23077.diff added

comment:3 Changed 4 years ago by linovia

Doesn't the patch prevents any load data for migrated application ?
I mean, it looks like Django wouldn't be able to use loaddata for any migrated application which I is not something we want, do we ?
All I can see in the release notes is that initial_data shouldn't be possible for migrated apps.

comment:4 Changed 4 years ago by Tim Graham

I agree with @linovia. I looked at it briefly and I think we could probably pass the test_database flag from migrate to loaddata (via flush) and check that before skipping initial data for apps with migrations.

comment:5 Changed 4 years ago by merb

ouch i've just seen some easier way maybe.

check that patch...

https://code.djangoproject.com/attachment/ticket/23077/new-23077.diff

If totally overseen the load_initial_data flag

Edit: now it won't load initial_data on migrate (which is the behavior told in the docs)

Last edited 4 years ago by merb (previous) (diff)

Changed 4 years ago by merb

Attachment: new-23077.diff added

comment:6 Changed 4 years ago by merb

if this is the desired behavior i would write a test, that tests the test runner.

comment:7 Changed 4 years ago by Tim Graham

Cc: Tim Graham added
Has patch: set
Needs tests: set

Looks good to me.

comment:8 Changed 4 years ago by Tim Graham

It may be easier/simpler to keep the test localized to the migrate command instead of testing the behavior indirectly through the test runner.

comment:9 Changed 4 years ago by Andrew Godwin

Owner: changed from nobody to Andrew Godwin
Status: newassigned

That patch will disable initial data loading for _all_ apps - it should be disabled for just the ones with migrations. I'll modify flush to only load apps mentioned in loader.unmigrated_apps.

comment:10 Changed 4 years ago by Andrew Godwin

After actually looking into this, there is no way to prevent people mentioning models that are migrated in fixtures in unmigrated apps (Django doesn't segregate models during fixture loading), so I'm going to say this is still a documentation issue and that you should just delete the initial_data fixtures from your migrated apps.

Additionally, I'm going to start initial_data on the deprecation path, so if you run with pending deprecation warnings turned on you'll see errors (and you'll definitely see them in 1.8).

comment:11 Changed 4 years ago by Andrew Godwin

Resolution: invalid
Status: assignedclosed

comment:12 Changed 4 years ago by Andrew Godwin <andrew@…>

In 2bacc9f3b70e45b172675452b7dd32900fbb8a8b:

[1.7.x] Mark initial_data as deprecated separately from syncdb. Refs #23077.

Conflicts:

docs/internals/deprecation.txt

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