Closed (fixed)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Order
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
22 Apr 2020 at 16:11 UTC
Updated:
7 May 2020 at 09:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jsacksick commentedComment #3
jsacksick commentedHere's a test demonstrating the failure.
Comment #4
jsacksick commentedComment #6
jsacksick commentedNote that we should probably open a core issue as well, since it doesn't make sense to allow saving reference to deleted entities.
Comment #7
jsacksick commentedComment #9
jsacksick commentedCommitted the fix!
Comment #10
amateescu commentedCore prevents references to non-existent (possibly deleted) items in the entity validation step. It is always necessary to call
validate()and check if there any violations before saving an entity.Given that, I'm not sure the fix is actually fixing anything..
Comment #11
jsacksick commentedWell, the test I wrote shows what I'm fixing. If an order item is being removed, the reference to it is never going to be "cleared". It's non controversial and fixed issues I experienced myself on a headless site, with saves over JSON API where the order is being validated.
Comment #12
agoradesign commented@jsacksick you've actually committed new test code + some comments in the order storage, as you've commented out the fix:
Comment #14
jsacksick commented@agoradesign: I'm terrible, thanks for watching out :) .
Comment #15
amateescu commented@jsacksick, the problem with the test is that it's not testing a real-world scenario. You need to change the test so it calls
validate()/code> before <code>save(), and don't try to save if there are any violations found.Comment #16
agoradesign commentedYou're welcome :)
Why isn't that real-world? If the test doesn't lead to having validate() called, why should that be guaranteed in real world? I'm unsure baout that assumption
Comment #17
amateescu commented@agoradesign, because the entity system does not (and can not) guarantee data integrity if you don't validate an entity before saving it, that's how the Entity API works. Any real world code that calls
save()without validating before is broken and needs to be fixed.Comment #18
jsacksick commented@amateescu: Well to me the fix is non controversial, there's probably broken code somewhere without a doubt, but at least this will limit the impact of making such a mistake...
And this isn't the only usecase the patch is addressing. If an order item is being deleted, the next time the order will be saved, the reference will remain, and that code fixes that.
Rather than putting this issue to "needs work" endlessly, we should probably. open other issues for the broken code we find :p.
Comment #19
jsacksick commentedRelated issues: #3130011: Clear broken order items reference on presave.
IMO the best approach to solving these kind of problems is to implement locking.
We have an issue for that (#2656818: Implement optimistic locking for orders), and that's the appropriate fix, however, the patch there is still not "ready", and that I think will "mitigate" the issue a little bit.
Comment #20
amateescu commentedIMO the fix is not ok because it prevents the actual bugs from being discovered at all by hiding the problem under the rug. This means that there are way less chances to find instances of broken code and open issues for them.
If removing an order item outside of a "cart context" is a problem, then the deletion should be prevented by the order item storage.