Expose content_version for optimistic locking on issue and PR edits#37035
Expose content_version for optimistic locking on issue and PR edits#37035wxiaoguang merged 5 commits intogo-gitea:mainfrom
Conversation
Add content_version field to Issue and PullRequest API responses. Accept optional content_version in edit endpoints — returns 409 Conflict when stale, succeeds silently when omitted.
When a PATCH updates both title and body with a stale content_version, the title change would succeed before the body update returned 409. Add an upfront version check before any mutations so the entire request is rejected early if the version is stale. The DB-level check in ChangeContent remains for concurrent request safety. A full transaction wrapping all mutations would be the complete fix, noted as a TODO.
|
Overall looks good to me. btw: next time you can ask your AI to use modern go like this: f5cbba9 |
bircni
left a comment
There was a problem hiding this comment.
lgtm - I don't see why I would use this but ok
There was a problem hiding this comment.
Three things I noticed:
-
Breaking change: 400 → 409 status code — The error response for
ChangeContentversion conflicts changed fromhttp.StatusBadRequesttohttp.StatusConflictin bothissue.goandpull.go. This affects all requests hitting the DB-level version check, not just those opting into the newcontent_versionfield. Any existing API client handling 400 for this error will break. While 409 is semantically more correct, this should be called out as a breaking API change. -
No tests for the pull request endpoint —
testAPIIssueContentVersiononly covers the issue edit path. The PR edit endpoint has identicalcontent_versionlogic but no test coverage. -
Missing swagger description annotations — The new
ContentVersionfields in the response structs (Issue,PullRequest) and edit option structs lack swagger description comments. Most other fields in these structs have doc comments describing them.
This comment was written by Claude Opus 4.6.
|
status code change I wouldn't consider breaking, so skip that one. |
|
Why merge with unaddressed comments? Do you reject them? |
I thought you meant that there is no concern anymore. To me:
|
I will add some tests for PR edit |
|
I meant skip 1, but do 2 and 3, sorry if it was unclear. |
|
Maybe it's better to convert a "lgtm/done" PR to WIP when there are still concerns to address. -> Add tests for pull request's content_version in API #37044 I am not sure how to do 3, feel free to edit the PR directly. |
|
Done in a7e5a90. I see we lack |
* main: Refactor issue sidebar and fix various problems (go-gitea#37045) Add tests for pull request's content_version in API (go-gitea#37044) Enable concurrent vitest execution (go-gitea#36998) Fix theme discovery and Vite dev server in dev mode (go-gitea#37033) bump snapcraft deps (go-gitea#37039) Expose content_version for optimistic locking on issue and PR edits (go-gitea#37035)
No one wants their work overwritten by accident. Allow the API to check before it writes.
Major Changes
content_versionfield to Issue and PullRequest API responsescontent_versioninPATCH /repos/{owner}/{repo}/issues/{index}andPATCH /repos/{owner}/{repo}/pulls/{index}— returns 409 Conflict when stale, succeeds silently when omitted (backward compatible)content_versionbefore any mutations to prevent partial writes (e.g. title updated but body rejected)Written with Claude Code and Opus, reviewed by human.