Repository navigation
OpenConceptLab/ocl_issues#3001 | deleting a locked repo version is recorded and reported as locked_version_deleted (stacked on #1031) - #1032
Conversation
…n each expansion locked to it, and health reports locked_version_deleted
snyaggarwal
left a comment
There was a problem hiding this comment.
Verdict: not ready to merge yet. One important finding, which is Jon's, and one nit on 78ecad0.
What I checked and found sound:
- The delete path: the record is written before the rows go, after the only-version check. Deleting a whole source covers its versions, and an organization delete goes through
source.deleteinside a transaction. - Explicit versions: only evaluated versions (locks) are recorded. A version only listed as explicit shows up as unresolved anyway.
- Saves: a save from an older copy can't wipe the record.
- Clearing: a rebuild from scratch clears it. The re-add after a removal doesn't, because it isn't a from-scratch rebuild.
- New versions:
lockcopies HEAD's record andlatestdoesn't. - The field: it isn't exposed by any serializer, only through health. The migration adds the column with a constant default.
The important finding is Jon's point: the reason names deleted versions to anyone who can view the collection, including another owner's private one (inline). It's cheap to fix, so it can go in before Dec 1.
| if len(version_ids) > 1 and from_unversioned) | ||
| add('duplicate_repo_versions', len(duplicates), repositories=duplicates) | ||
| deleted_locks = self.expansion.deleted_locked_repo_versions or [] | ||
| add('locked_version_deleted', len(deleted_locks), versions=sorted({entry['url'] for entry in deleted_locks})) |
There was a problem hiding this comment.
Important: the reason can expose another owner's private version. Jon's point on OpenConceptLab/ocl_online#549, confirmed here. versions lists every recorded URL, and #1029 serves health to anyone who can view the collection. If org A's public collection was locked to org B's private /orgs/B/sources/Secret/v3/ and B deletes v3, any viewer of A's collection sees that URL.
Fix: at delete time, record whether the version was public and who owned it. List a URL only when the version was public or the collection's owner's own (the owner's-view rule the classifier already uses for releases), and count the rest without naming them.
Nit (optional), on the same line: a retried delete double-counts. count is the number of entries while versions is a set. A version delete isn't atomic and is written to be retried, so a retry appends the same version again. Counting unique URLs would fix it.
…rsions the collection's owner could see, and counts each once
|
Both review points are fixed in the latest commit. The description is updated.
There are three new tests:
77 tests pass locally, and |
snyaggarwal
left a comment
There was a problem hiding this comment.
Verdict: ready to merge once CI passes and #1031 has landed. No findings on 048f8f5.
Both fixes check out:
- Private versions (Jon's point): each record keeps the deleted version's owner and whether it was public.
locked_version_deletednames a version only when it was public or the collection owner's own, the same owner's-view rule the classifier applies to releases, and counts the rest without naming them. Records without the new keys count as private, which is the safe default. - Double count:
countcounts each version once, so a retried delete doesn't inflate it.
The new tests cover both, and I found nothing else across the PR.
Still open, and not part of the code: the owner's rebuild offer is TBv3 work (OpenConceptLab/ocl_issues#3004 and OpenConceptLab/ocl_issues#3009). The merge order is the health stack (#1025, #1026, #1029, #1031), then this PR.
…leanup task, as CI has no broker
|
CI fix in the latest commit. Deleting a version queues |
paynejd
left a comment
There was a problem hiding this comment.
Review at c242af4. An independent defect pass (Codex, high effort), with every finding checked against the code. The owner's-view point from this morning is fixed and not repeated.
Verdict: approve. Members don't change, and the record matches the Nov 3 decision. One point is worth doing so owners see the warning when it matters.
Worth fixing
- The warning waits for the next change. Delete marks health not current and records the lock (
common/models.py~987, ~1010), but queues no recompute.locked_version_deletedappears only when health is next computed. For a HEAD expansion that's the next add, which has already fallen back to the latest release by then. A frozen release never gets one. With the toggle on, queue the debouncedcompute_expansion_healthon commit for each affected expansion:record_deleted_locksalready has the ids, and these deletes are rare. publicshould useis_publicly_viewable(collections/models.py~2564-2573). A version keeps its own flag after its HEAD goes private, and the HEAD still exists when the record is written. Suggestion inline. It's the same rule as #1025's point 2.- The record is written before the delete succeeds.
record_deleted_lockscommits under autocommit beforeunlink_url_registry_entriesandsuper().delete(). If the delete then fails, the release survives but is recorded as deleted, and nothing clears it. Write the record aftersuper().delete()succeeds, or put both in one transaction.
Minor
4. A from-scratch rebuild clears the record before it runs (~1960). If the rebuild then fails, the record is lost, although a failed rebuild already leaves bigger problems on master. Optional: clear it once the rebuild succeeds.
Two things found on master along the way aren't this PR's, and are filed: ocl_issues#3062 (a hard-deleted user's repositories skip their delete steps) and ocl_issues#3063 ($clone accepts a release as its target).
| from core.common.models import BaseModel | ||
| deleted_at = timezone.now().isoformat() | ||
| for version in repo_versions: | ||
| kind = 'collection' if isinstance(version, Collection) else 'source' | ||
| through = getattr(cls, f'evaluated_{kind}_versions').through | ||
| entry = { | ||
| 'url': version.uri, 'repo_url': drop_version(version.uri), 'version': version.version, | ||
| 'type': version.resource_type, 'deleted_at': deleted_at, 'owner_url': version.parent_url, | ||
| # health names it only where it was visible, as the version is gone by the time anyone asks | ||
| 'public': version.public_access in BaseModel.PUBLIC_ACCESS_VALUES} |
There was a problem hiding this comment.
Point 2: records public with is_publicly_viewable, so a release whose HEAD is private counts as private, and drops the import it no longer needs.
| from core.common.models import BaseModel | |
| deleted_at = timezone.now().isoformat() | |
| for version in repo_versions: | |
| kind = 'collection' if isinstance(version, Collection) else 'source' | |
| through = getattr(cls, f'evaluated_{kind}_versions').through | |
| entry = { | |
| 'url': version.uri, 'repo_url': drop_version(version.uri), 'version': version.version, | |
| 'type': version.resource_type, 'deleted_at': deleted_at, 'owner_url': version.parent_url, | |
| # health names it only where it was visible, as the version is gone by the time anyone asks | |
| 'public': version.public_access in BaseModel.PUBLIC_ACCESS_VALUES} | |
| deleted_at = timezone.now().isoformat() | |
| for version in repo_versions: | |
| kind = 'collection' if isinstance(version, Collection) else 'source' | |
| through = getattr(cls, f'evaluated_{kind}_versions').through | |
| entry = { | |
| 'url': version.uri, 'repo_url': drop_version(version.uri), 'version': version.version, | |
| 'type': version.resource_type, 'deleted_at': deleted_at, 'owner_url': version.parent_url, | |
| # health names it only where it was visible, as the version is gone by the time anyone asks | |
| 'public': version.is_publicly_viewable} |
# Conflicts: # core/collections/models.py
… the delete succeeds, as publicly viewable or not, recomputes health at once, and a rebuild clears it only when done
|
Thanks, Jon. All four points are addressed in the latest commit, on a merge of the backfill branch (c4d0451). The merge conflict, over the health fields, was resolved in its own commit.
The local Elasticsearch container is down, so CI is the first test run. |
paynejd
left a comment
There was a problem hiding this comment.
Thanks, Sunny. All four points are met:
- The recompute is queued once the delete succeeds.
publicisis_publicly_viewable, read while the HEAD still exists.- The record is planned before the delete and written after it.
- A failed rebuild keeps the record.
The merge resolution keeps both sides. It has health_revision, the three health fields, deleted_locked_repo_versions and the separately written fields, and the migrations chain 0074 then 0075. #1026's repository marking survives the move into before_repository_delete, which now runs after the only-version check.
One edge, fine to leave: a locked version deleted between a rebuild re-adding it and the rebuild clearing the record is cleared along with the rest.
Approved, once CI is green.
|
CI: the failing health tests came from the branches below. Their fixes are merged in (3e90372). No change on this branch. |
For OpenConceptLab/ocl_issues#3001 (epic OpenConceptLab/ocl_issues#2942). It's stacked on #1031, the last PR of the expansion health stack (OpenConceptLab/ocl_issues#3003).
Deleting a repo version deletes the rows that lock expansions to it, so a later add quietly falls back to the latest release. Afterwards nothing shows it happened. This PR records the deletion at delete time and reports it as a health reason. As Jon decided on Nov 3, it isn't an
unresolved_repo_versionsentry, so FHIR$expandkeeps answering.What changes
Expansion.deleted_locked_repo_versionsfield holds one entry per deleted lock:url,repo_url,version,type(SourceorCollection),deleted_at, and the version'sowner_urland whether it waspublic. Migration0075adds it.ConceptContainerModel.deletecallsExpansion.record_deleted_locks. That adds an entry to each expansion whose evaluated list (its lock) holds the version, with oneUPDATEper deleted version. Deleting a whole source or collection records each of its locked versions.locked_version_deleted, makes the stateunhealthy. Itscountcounts each deleted version once, so a retried delete doesn't double it. Itsversionsnames only those that were public or the collection owner's own, the owner's-view rule the classifier uses for releases. Health is shown to anyone who can view the collection, so another owner's private version is counted but not named. As before, the delete marks those expansions' health not current. Their next change recomputes it, or the backfill does.lockcopies HEAD's record, because it's built under HEAD's remaining locks. One created withlatestdoesn't.Not in this PR
The rebuild offer for the expansion's owner belongs in TBv3: the badge (OpenConceptLab/ocl_issues#3004) and the rebuild offer (OpenConceptLab/ocl_issues#3009). The API already has the rebuild.
Tests
core/collections/tests/tests_deleted_locks.pyhas 11 tests:lockcopies it into a new version andlatestdoesn't.Locally, these and the health and backfill tests pass: 77 tests. So do the 575 tests in
core.collections.tests.testsandcore.sources.tests.makemigrations --checkfinds nothing missing, andpylint -j0 core/exits 0.🤖 Generated with Claude Code