GenericForeignKey does not allow content type PK 0
|Reported by:||devesine||Owned by:||woodlee|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The GenericForeignKey system does not properly recognize when a ContentType ID 0 is linked to. In django/contrib/contenttypes/generic.py, two specific instances are checking for "if primarykey:" rather than "if primarykey is not None:".
This specifically came up in our environment because we are matching the ContentType ids to our legacy database content type ids, which start at 0 rather than 1.
To reproduce, rename attached foobar_models.py to models.py and place in an app named 'foobar', then follow the directions in comments at the bottom of the models file.
The attached proposed patch changes these two if statements to "is not None", which I believe is more correctly in the spirit of the code as well as allowing this functional case.
Change History (23)
comment:1 Changed 4 years ago by russellm
- Needs tests set
- Triage Stage changed from Unreviewed to Accepted
comment:3 Changed 3 years ago by gabrielhurley
- Component changed from Contrib apps to contrib.contenttypes
comment:9 Changed 20 months ago by woodlee
- Owner changed from nobody to woodlee
- Status changed from new to assigned
comment:15 Changed 17 months ago by anonymous
- Triage Stage changed from Accepted to Design decision needed
comment:17 Changed 16 months ago by aaugustin
- Triage Stage changed from Design decision needed to Accepted