local_variables_are_none() check in Reference.__get__() not always appropriate
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Storm |
New
|
Undecided
|
Unassigned |
Bug Description
Michael Hudson brought this problem to my attention today on IRC. Attached is a patch to add a test case.
The Reference.__get__() method includes a check to see if the local variables are None, and immediately return None if that is the case. This is intended to avoid querying the remote table when it is clear that the local key won't match any records.
However, if the reference has on_remote=True and the local variables are the local primary key, then the local variables being None could also indicate that the object is in pending add state. If the store were to be flushed and a primary key to be assigned, a remote object may be found.
This can happen if we have Reference() attributes going in both directions and the other reference was set to link the objects, as demonstrated in the attached test case.
Related branches
tags: | added: tech-debt |
I've attached a branch that fixes this problem, but causes the test_reference_ wont_touch_ store_when_ key_is_ unset test to fail.
I am not convinced that the behaviour that test checks is desirable though, so the fix might be to remove that test.