Fixed member deletion errors from concurrent API requests#26647
Fixed member deletion errors from concurrent API requests#26647kevinansfield merged 1 commit intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThe MemberRepository.destroy implementation was changed to merge 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/core/server/services/members/members-api/repositories/member-repository.js (1)
815-816: Message-based error matching has limited alternatives in Bookshelf 1.2.0.The
"No Rows Deleted"check at line 815 is brittle across ORM/version changes, as suggested. However, Bookshelf 1.2.0 does not expose a stable error code or custom error class for this specific case (unlike database constraint errors which useerr.code). This pattern is also used consistently elsewhere in the codebase (e.g.,donation-checkout-session.test.js) and is well-tested. Consider upgrading to a newer Bookshelf version or adding a comment documenting this limitation if an alternative discriminator becomes available.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/core/server/services/members/members-api/repositories/member-repository.js` around lines 815 - 816, The string-equality check if (err.message === 'No Rows Deleted') is brittle because Bookshelf 1.2.0 exposes no stable error code/class for this case; update the member-repository.js where this check appears to add a clear comment above the check stating that Bookshelf 1.2.0 only exposes the message (hence the message-based match), referencing the fact this pattern is used elsewhere (e.g., donation-checkout-session.test.js), and note that upgrading Bookshelf or replacing this check with a proper discriminator should be done when a newer Bookshelf version/error API is available; leave the existing conditional otherwise to preserve current behavior and tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@ghost/core/core/server/services/members/members-api/repositories/member-repository.js`:
- Around line 815-816: The string-equality check if (err.message === 'No Rows
Deleted') is brittle because Bookshelf 1.2.0 exposes no stable error code/class
for this case; update the member-repository.js where this check appears to add a
clear comment above the check stating that Bookshelf 1.2.0 only exposes the
message (hence the message-based match), referencing the fact this pattern is
used elsewhere (e.g., donation-checkout-session.test.js), and note that
upgrading Bookshelf or replacing this check with a proper discriminator should
be done when a newer Bookshelf version/error API is available; leave the
existing conditional otherwise to preserve current behavior and tests.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
ghost/core/core/server/services/members/members-api/repositories/member-repository.jsghost/core/test/unit/server/services/members/members-api/repositories/member-repository.test.js
🤖 Velo CI Failure AnalysisClassification: 🟠 SOFT FAIL
|
allouis
left a comment
There was a problem hiding this comment.
This can be simplified a little, but it's not blocking
| try { | ||
| return await this._Member.destroy({ | ||
| id: data.id | ||
| }, options); |
There was a problem hiding this comment.
You can pass {...options, require: false} here and avoid the whole try/catch and error inspection
refs https://linear.app/ghost/issue/ONC-1516 When multiple DELETE requests for the same member arrive concurrently, the second request's destroy() fails because the row is already gone. Pass `require: false` to Bookshelf's destroy so it treats this as a no-op.
4ed40d9 to
c009de6
Compare
Summary
DELETE /members/{id}requests target the same member concurrently, a race condition causes Bookshelf to throw "No Rows Deleted" errors that bubble up as 500s to SentryfindOnecheck passes for both requests (member exists), but by the time the second request'sdestroy()runs, the member is already gonerequire: falseto Bookshelf'sdestroy()so it treats a missing row as a no-op — the member is already deleted, which is the desired outcomerefs https://linear.app/ghost/issue/ONC-1516