Open lukearndt opened 2 months ago
have deployed to nz-dev but it does not appear to work as intended/expected:
having disabled the client-side check (that normally ensures that only one category is assigned when multiple are not allowed), I tried to assign multiple categories (progress status taxonomy where allow_multiple = false) to an action which is triggering as many CREATE requests.
expected outcome: the action will have only one category assigned, i.e. from the latest request
observed outcome: the action appeared to (a) have all categories assigned on the client (as all requests yielded a positive response with the newly created association) however (b) it appears that sometimes NONE of the associations were actually stored in the database. further (c) it appears that assigning a single-association-category that ALL previous category associations including from other taxonomies are being removed
before assignment:
after assignment:
after page reload all associations are gone (illustrating (b) and (c))
after page reload (illustrating (c)):
ad a) although I didn't expect this, it makes sense the way we specified it, i.e. if each request replaces the former connection, the previous responses will yield a positive result (not knowing that it will be removed the next moment). unless we change the implementation (i.e. use one request to create multiple connections), this is mostly a client side issue (which would be prevented from only requesting to create one association at a time). could leave as is for now as long as the database will be valid
ad b) not sure why this is sometimes happening
ad c) please make sure that only categories from the same taxonomy are destroyed (think this is where the issue lies https://github.com/impactoss/impactoss-server/pull/417/files#diff-98cc269f45b5a8127b196083487b9fcfc6357763c8f4568057c5ff0c30ca0b39R35)
@tmfrnz I have completed an update that applies the rules as I now understand them, with extensive specs.
Could you please verify that it now works as intended?
it appears that only categories of the same taxonomy are deleted now for those taxonomies. however it also looks like that still sometimes no category assignment remains (of the same taxonomy) when assigning multiple categories at once (in reality 3 separate, concurrent requests)
my suspicion is that the after_commit hooks sometimes run after all PUT requests (commits) are processed and then deleting all respective other categories
I've changed the callback to around_save
and wrapped it in a transaction. I expect that this will prevent multiple updates in quick succession from leading to incorrect data.
To verify that, I've updated the specs to apply multiple changes quickly across different threads. These new specs failed with the old after_commit
implementation, and pass with the new around_save
version.
I think this is good now. I've tested a ton of different combinations and cases, and everything functioned as I expected it to.
Context
https://github.com/impactoss/impactoss-server/issues/379
From the linked issue:
Additional context from Timo via Slack:
Changes
This commit enforces the
allow_multiple
setting on Taxonomies for the following relation models:In each case, it achieves this using a
save_with_cleanup
method that we need to call instead of the usualcreate
orsave
.This commit also makes the controllers for these relations respond to
destroy
requests on missing records as though they had succeeded.