Repository navigation
OpenConceptLab/ocl_online#874 | Concept updates clean up by version, and new rows take their source's access - #1130
Conversation
…and new rows take their source's access - SourceChildMixin.take_back() deletes the version it's called on. The version it replaced becomes the latest again, with HEAD as it was, unless a newer one exists. A concept update with mappings uses it for the concept and for each mapping it saved, then recounts the source's mappings and indexes the concepts they were of, once. - Each entry of an update's mappings must be an object. - keep_source_access_on_commit() runs after a new row's last full save, and ConceptDetailSerializer.parent_id is an IntegerField, as in MappingDetailSerializer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qTEw8c6qZh5C69F1V4
|
Reviews: three Codex passes (codex-cli 0.171.0), two Codex checks of the later commits, a simplification review and an access review, all before the commits were put together. Every P1 is fixed. Of the twelve P2s from Codex, seven are fixed and five accepted. The findings, with an answer to each, are on OpenConceptLab/ocl_online#874. |
snyaggarwal
left a comment
There was a problem hiding this comment.
Verdict: the code is ready to merge. Merge it after #1117. I'm posting this as a comment instead of an approval only because the PR is stacked on #1117 (its base is OpenConceptLab/ocl_online#654-owner-checks), and the body says #1117 merges first. Once #1117 is in and this is retargeted to master, it can go in as is. CI (Pylint, Tests, Snyk) is green and there are no conflicts with its base. The two notes below are nits and don't block. It doesn't depend on #1122 either way: both touch core/mappings/models.py, but in separate hunks.
What I checked:
- Item 3, retired mappings. The old
_rollback_mapping_operationsnever undid a__delete: it was queued under'action'and read back as'__action'. Savinglast_retire_versionand taking it back fixes that.__update_retiregoes throughsave_as_new_version, soreplacedis set beforetake_backreads it. - Item 4, taking back only its own version.
take_backdeletes only the version it's called on. It restores the version it replaced (or the nearest earlier one, active or not;versionsexcludes HEAD, so HEAD is never chosen), and only when the failed version is still the latest. Otherwise the newer update is left alone. The tests cover both orders of a concurrent update, two failed updates at once, and HEAD's external ID. - Lock order.
take_backlocks the source, then HEAD, which matches an access edit.save_as_new_versionlocks HEAD and never writes the source row:mark_child_removalonly runs on a delete, and that happens outside its atomic block. So a failed update being taken back while another update is saved can't deadlock. - Item 1, access.
keep_source_access_on_commitnow runs after each row's last full save, for new and cloned concepts and mappings.NewResourceSourceAccessTestchecks all four at every point in the save.ConceptDetailSerializer.parent_idbecoming anIntegerFielddoesn't let a client pick the source: create replacesparent_idwith the URL's source (views.py:335), andcreate_new_version_fornever reads it. - Counts and search. After a failed update the mappings are recounted once, and the concepts the mappings belonged to are reindexed once, after everything is back.
Jon's Codex, simplification and access reviews on OpenConceptLab/ocl_online#874 already cover the deadlock, a malformed entry, the external ID, overlapping rollbacks and indexing. I'm not raising those again, and the five accepted P2s look reasonable to me.
One optional nit, not on a changed line: ConceptDetailSerializer.mappings_payload could use ListField(child=DictField()). A non-object entry would then get a field-level 400 that says which item is wrong. The model check is still worth keeping for callers that don't go through the serializer.
| Deletes this version, saved by an update that then failed. The version it replaced is the latest again and HEAD | ||
| is as it was, unless another update has made a newer version since. | ||
| """ | ||
| replaced_id, external_id = self.replaced |
There was a problem hiding this comment.
Nit: take_back only works on the same in-memory object that save_as_new_version saved, because replaced is set by _lock_and_get_latest_versions. A version loaded from the database gets an AttributeError here. Every caller today meets that condition, but a sentence in the docstring would stop someone from calling it on a re-fetched row later.
Refs OpenConceptLab/ocl_online#874. Built on #1117, which merges first.
What the code does now
SourceChildMixin.take_back()deletes the version it's called on, under the locks on its source and on HEAD. The version it replaced is the latest again, with HEAD as it was, unless there's a newer one. A concept update uses it for the concept and for each mapping it saved, then recounts the source's mappings and indexes the concepts they were of, once. It replacesrollback_latest_version_to()and the list of operations.mappingsin a concept update must be objects. The answer is a 400 otherwise.keep_source_access_on_commit()runs after a row's last full save, andConceptDetailSerializer.parent_idis anIntegerField, as it is for mappings.Why not one transaction for the whole update: saving a mapping queues its indexing and count tasks at once, so they would run before the commit.
Tests: 4,307 pass, and pylint is clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qTEw8c6qZh5C69F1V4