[Django] #23582: Django 1.7 initial data can't relies on other apps one.

9 views
Skip to first unread message

Django

unread,
Oct 2, 2014, 2:15:12 AM10/2/14
to django-...@googlegroups.com
#23582: Django 1.7 initial data can't relies on other apps one.
----------------------------+-------------------------------------
Reporter: Nicals | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords: initial data,migrations
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------------------
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.

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

Django

unread,
Oct 2, 2014, 8:03:19 AM10/2/14
to django-...@googlegroups.com
#23582: Django 1.7 initial data can't relies on other apps one.
-------------------------------------+-------------------------------------
Reporter: Nicals | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.7
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: initial | Needs documentation: 0
data,migrations | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* component: Migrations => Documentation
* needs_tests: => 0
* needs_docs: => 0
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

In the section on [https://docs.djangoproject.com/en/1.7/topics/migrations
/#data-migrations data migrations], we could describe how to use
dependencies to enforce the order in which migrations are executed and
link to the section on
[https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies
migration dependencies]. We should also document the caveat with data
created in `post_migrate` signals as noted in #23422.

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

Django

unread,
Oct 28, 2014, 10:08:12 AM10/28/14
to django-...@googlegroups.com
#23582: Django 1.7 initial data can't relies on other apps one.
-------------------------------------+-------------------------------------
Reporter: Nicals | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: 1.7
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: initial | Needs documentation: 0
data,migrations | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by maximvl):

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, 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?

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

Reply all
Reply to author
Forward
0 new messages