Opened 12 years ago

Last modified 3 weeks ago

#23582 assigned Cleanup/optimization

Django 1.7 initial data can't relies on other apps one.

Reported by: Nicals Owned by: Prince Verma
Component: Documentation Version: 1.7
Severity: Normal Keywords: initial data, migrations
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In django 1.7, we are told to create initial data using datamigrations instead of fixtures.

But if those initial data depends on other initial data that are created during a post_migrate signal catch we can't access them. Same thing if I need to relies on other apps initial data create on a datamigration : I never know in which order these data are created.

A typical scenario I'm facing:

I need a group spam_user_group that have some django.contrib.admin autogenerated permission in it. I can't relly on python script in datamigration to fetch the Permission I need because their are created within a post_migrate signal.

If I try to create those migrations in my own post_migrate signal handler, I can't be sure that my script will be executed after django.contrib.admin ones.

---

Maybe I've misunderstood the documentation about this point, but after a lot of tries and fails I couldn't find a clean way to achieve the scenario I'm presenting here. Maybe this tickets is not a bug, but in this case some documentation about that is to be added.

Change History (5)

comment:1 by Tim Graham, 12 years ago

Component: Migrations → Documentation
Triage Stage: Unreviewed → Accepted
Type: Bug → Cleanup/optimization

In the section on ​data migrations, we could describe how to use dependencies to enforce the order in which migrations are executed and link to the section on ​migration dependencies. We should also document the caveat with data created in post_migrate signals as noted in #23422.

comment:2 by Maxim V, 12 years ago

Hi Nicals, I have exactly same problem. My custom data depends on permissions which created on post migrate hook. The obvious solution is to have some kind of sort, for dispatch_uid for example, of receivers in dispatch/dispatcher.py class Signal, method send. When you can check signals you want to rely on and choose appropriate dispatch_uid for your own connections.
What do you think?

Last edited 12 years ago by Maxim V (previous) (diff)

comment:3 by Prince Verma, 3 weeks ago

Owner: changed from nobody to Prince Verma
Status: new → assigned

comment:4 by Prince Verma, 3 weeks ago

​PR adds the documentation clarification. The documentation build passed, and I checked the rendered page.

comment:5 by Prince Verma, 3 weeks ago

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