Skip to content

OpenConceptLab/ocl_online#874 | Concept updates clean up by version, and new rows take their source's access - #1130

Open
paynejd wants to merge 1 commit into
OpenConceptLab/ocl_online#654-owner-checksfrom
OpenConceptLab/ocl_online#874-small-fixes
Open

paynejd wants to merge 1 commit into
OpenConceptLab/ocl_online#654-owner-checksfrom
OpenConceptLab/ocl_online#874-small-fixes

Conversation

@paynejd

@paynejd paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member

Refs OpenConceptLab/ocl_online#874. Built on #1117, which merges first.

What the code does now

  • Concept updates with mappings: 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 replaces rollback_latest_version_to() and the list of operations.
  • Entries of mappings in a concept update must be objects. The answer is a 400 otherwise.
  • New and cloned concepts and mappings: keep_source_access_on_commit() runs after a row's last full save, and ConceptDetailSerializer.parent_id is an IntegerField, 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

…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
@paynejd
paynejd requested a review from snyaggarwal December 4, 2026 09:46
@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

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 snyaggarwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_operations never undid a __delete: it was queued under 'action' and read back as '__action'. Saving last_retire_version and taking it back fixes that. __update_retire goes through save_as_new_version, so replaced is set before take_back reads it.
  • Item 4, taking back only its own version. take_back deletes only the version it's called on. It restores the version it replaced (or the nearest earlier one, active or not; versions excludes 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_back locks the source, then HEAD, which matches an access edit. save_as_new_version locks HEAD and never writes the source row: mark_child_removal only 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_commit now runs after each row's last full save, for new and cloned concepts and mappings. NewResourceSourceAccessTest checks all four at every point in the save. ConceptDetailSerializer.parent_id becoming an IntegerField doesn't let a client pick the source: create replaces parent_id with the URL's source (views.py:335), and create_new_version_for never 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.

Comment thread core/common/mixins.py
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants