Document that F expressions are reapplied each time an object is saved
|Reported by:||codefisher||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I would have thought these two expresses would be exactly the same, except the second would be more efficient.
A: some_model.some_field += 1
B: some_model.some_field = F('some_field') + 1
I hit some unexpected behaviour when, I did this
# and somewhere far far away
With A, the field is incremented once, as I expected. But with B, it gets incremented twice. I would have expected the F query to effect the next database call, and nothing more. It might be intended, but then it is not documented.
I could write some come to demonstrate this. I only noticed it because I was using an import script that was creating lots of objects, and I had A and B in the model's overridden save method. They were causing vastly different results.
Change History (6)
comment:1 Changed 6 months ago by codefisher
- Component changed from Uncategorized to Database layer (models, ORM)
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 6 months ago by timgraham
- Component changed from Database layer (models, ORM) to Documentation
- Summary changed from Unexpected result when incrimenting field with F expression to Document that F expressions are reapplied each time an object is saved
- Triage Stage changed from Unreviewed to Accepted
- Type changed from Uncategorized to Cleanup/optimization