GenericForeignKey does not allow content type PK 0
|Reported by:||Justin de Vesine||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.