fix: fall back to create+delete when a draft tag rename hits a duplicate-key 500 #49
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/47-draft-tag-rename-conflict"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes #47.
Since #44,
create_or_update_release()alwaysPATCHes the existing draft with the freshly computed tag, including a changedtag_namewhen the bump type escalates (e.g. patch → minor). Forgejo can answer that rename with an HTTP 500 unique-constraint violation on(repo_id, tag_name)even when no release or git tag with that name is visible through the API. Every subsequent run then fails identically — the action wedges.Root-cause verification
Confirmed against Forgejo's own source (
services/release/release.go,models/repo/release.go), not just the issue's hypothesis:For a draft,
createTag()'s whole body is skipped (no git ref is touched), butUpdateRelease()still doesAllCols().Update(rel), writing the newtag_namestraight to the DB regardless. TheReleasestruct hasTagName stringxorm:"INDEX UNIQUE(n)"`` on(RepoID, TagName)— that'sUQE_release_n, matching the error ('35-v0.1.0') exactly.So: the web UI's edit-release form never exposes a tag field on edit, which is why nobody hits this by hand — but the API's
PATCHhas no such guard and applies a changedtag_nameblind. This is a server-side gap exercised only by direct API clients like this action.This also explains the "invisible conflicting row":
Releasehas anIsTag boolfield — "true only if the record is a tag and has no related releases" — i.e. Forgejo keeps bookkeeping rows for raw git tags in the same table, sharing the same unique index.GET /releasesfiltersis_tag=falseandGET /tagsreads live git refs; neither surfaces an orphanedis_tag=truerow with no corresponding ref. That's consistent with everything observed on the reported repo (Aevana/aevana, read-only):GET /repos/Aevana/aevana/releases(unfiltered) and?draft=true: onlyv0.0.1...v0.0.8(published) andv0.0.9(the one draft, id 594). Nov0.1.0anywhere.GET /repos/Aevana/aevana/releases/tags/v0.1.0: 404.fj tag list/fj tag view v0.1.0: nov0.1.0git tag exists.I did not write-probe that repo (e.g. a throwaway
POST .../releaseswithtag_name=v0.1.0) to empirically confirm the fallback'sPOSTsucceeds, since it isn't mine. Given the source-level confirmation above —CreateReleasechecksIsReleaseExist(which itself likely filtersis_tag, same asymmetry) rather than blindly inserting — a freshPOSTfor the new tag should succeed where thePATCH-rename of a different row id cannot. Happy to run the probe with your go-ahead, or confirm on the next real run.Changes
check_for_conflicting_tag(): before a tag rename, checks both/releases/tags/{tag}and/tags/{tag}and logs what's found — including explicitly logging when neither shows anything, since that absence is itself the diagnostic signal for this failure mode.409/422/500from a tag-renamingPATCH, fall back tocreate_then_delete_old_draft():POSTa new draft for the new tag, thenDELETEthe stale draft by id. Retrying the identicalPATCHwould just reproduce the same deterministic conflict, so no retry loop was added.DELETEfails, raiseReleaseLookupErrorinstead of logging and continuing — otherwise a duplicate draft could accumulate silently across runs.ReleaseLookupErrormessages now include the method, URL, and a (body-truncated, to keep the "duplicate" case from dumping the entire rendered release notes) request payload, so a failure is reproducible from the logs alone.Intentionally not implemented from the issue's suggestions: a blind retry-once-for-5xx — retrying a deterministic unique-constraint violation just reproduces the same error.
Test plan
python3 -m astsyntax check passes.Aevana/aevana(or a deliberate patch→minor escalation on a repo with an existing draft) to confirm the fallback actually fires and succeeds.🤖 Generated with Claude Code