create_permisions(): Call to ContentType.objects.clear_cache() missing

95 views
Skip to first unread message

guettli

unread,
Aug 20, 2015, 5:31:46 AM8/20/15
to Django developers (Contributions to Django itself)
There is a six years old issue which has a working patch:

 https://code.djangoproject.com/ticket/10827

If a migration deletes and recreates content-types, then the automatically called create_migrations()
can result in ForeignKey constraint errors.

Example:

If Permission "Can add group" had primary key 1 before the migration and after the migration
it has the value 2, then things get broken.

The cache needs to be cleared first.

Please have a look at it.

Thank you,

  Thomas Güttler

Tim Graham

unread,
Aug 20, 2015, 7:14:21 AM8/20/15
to Django developers (Contributions to Django itself)
Hi Thomas, As indicated by the flags on the ticket, it "Needs tests" in order to be committed.

guettli

unread,
Aug 20, 2015, 9:47:45 AM8/20/15
to Django developers (Contributions to Django itself)
I wrote simple test for django before, but this is not easy. But maybe I am able do it, if I get some help.

The test would need to do the following:

1. Create a simple Model via migrations
2. implicit: ContentTypes and Permissions get created automatically.
3. Run migrations again.
4. This time a migration removes all exiting content-types and adds them again. But with different PKs.
5. implicit: New permissions created for an existing ContentTypes should be created. Up to now an exception happens. (See ticket).

How can I write a unittest which does the above steps?

Regards,
  Thomas

Tim Graham

unread,
Aug 20, 2015, 10:54:18 AM8/20/15
to Django developers (Contributions to Django itself)
I think you should aim for a lower level test which calls create_permissions() and update_contenttypes() in the order described in the ticket description. This problem precedes migrations, so I don't think there's a need to have that additional complexity in the test. Feel free to continue the discussion on the ticket or in #django-dev if you need further advice. Thanks!
Reply all
Reply to author
Forward
0 new messages