Open Wilfred opened 12 years ago
The FKNull fix modifies a lot of internal variables of the query (which is django.db.models.sql.Query here). When the query is reinitialized for the second call the table_map somehow reuses old columns lists (without the column that the fix removed) -- this already is bad.
Here's branch with a fix: https://github.com/django-nonrel/django-dbindexer/tree/feature/nullable-foreign-keys-with-slices It should be enough to change the table_map modification in unref_alias to modify a copy of list it contains:
query.table_map[table_name] = [t for t in query.table_map[table_name] if t != alias]
Moreover, it would be nice to just decrease the alias reference count in unref_alias (so we don't run into similar trouble with some future Django internal query code changes) -- but this would at least require more testing.
wrwrwr: are you happy with me merging this?
I suppose yes, but if you wouldn't mind I'll take a closer look and retest after I'm done with the type-conversion resplitting (just a few thousands more of diff lines to go ;-) This one could use clean up too -- just the unref_alias changes and the test are meaningful for the issue.
This fix won't work as-is with python2.5 as it uses collections.Mapping which was introduced in python 2.6
I'm testing with 2.5 (2.6 for Mongo) / 2.7 before pushing / merging now, so nothing like this should go unnoticed again :-) Can't see any Mapping on this branch, but going to reroll it anyway because too many insignificant changes have crawled in.
Does the patch still apply? I have the same problem and would really appreciate it if this patch got pushed.
This patch is still required (in the django nonrel 1.4 branch anyway). Oh, and it works a treat: thanks Wilfred.
This patch fixes the reported issue but it introduces a new one, i.e. some model is not validated. Does anyone have any idea why?
Error: One or more models did not validate:
admin.logentry: "idxf_object_id_l_exact": CharFields require a "max_length" attribute that is a positive integer.
I'm not completely sure what's going on but if I only replaces the unref_alias
function manually instead of downloading the patch's backends.py
, this error doesn't appear.
Given the models:
And given the following settings (note the FkNullFix):
Querying for null foreign keys generates the following crash:
Traceback: