Using dumpdata to create unit test fixtures causes duplicate foreign keys for auth permissions. Excluding auth causes other referenced auth models to be missing.
|Reported by:||ellisd23@…||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
This seems to be a pretty fundamental issue, since models will frequently reference User. There are many instances of users having frustrations with contrib apps that are auto-generated upon migration/sync (e.g. contenttypes).
For contenttypes, this issue can be mitigated by excluding the app and using --natural. But for contrib.auth, if the app is excluded, any referenced User objects in fixture data will be missing. If the app is not excluded, duplicate permissions will be created, since the post-migration signal will have already created them. Since there is a unique key restraint, the importing of the fixture data will fail. It's a catch 22.
Developers can manually remove the permissions from the fixture data, or override fixture loading in their tests to remove the data, but it seems to me that since this is such a basic piece of functionality, there should be a simple interface to do such a thing. It'd be nice to have something simpler for contenttypes as well, rather than "--exclude contenttypes --natural".
Change History (4)
comment:1 Changed 21 months ago by akaariai
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted