Skip to content

overwrite with version#198

Merged
thehabes merged 18 commits intomainfrom
197-overwrite-does-not-notify-requestors-if-the-version-they-are-overwriting-has-changed
Jul 1, 2025
Merged

overwrite with version#198
thehabes merged 18 commits intomainfrom
197-overwrite-does-not-notify-requestors-if-the-version-they-are-overwriting-has-changed

Conversation

@cubap
Copy link
Copy Markdown
Member

@cubap cubap commented Jun 24, 2025

  • adding version match for overwrite
  • testing locking
  • generated tests (not implemented)

To use:

  • add header "If-Overwritten-Version" with a value of the __rerum.isOverwritten property or include this property in the request (it will be discarded as usual, so it can be partial)
  • get a success if it matches or
  • fail with 409 if it doesn't match. error.currentVersion will supply the current version for a quick retry if you can easily diff what changes you would like.
  • retry until happy.

- adding version match for overwrite
- testing locking
- generated tests (not implemented)
@cubap cubap requested a review from thehabes as a code owner June 24, 2025 16:28
@cubap cubap marked this pull request as draft June 24, 2025 16:28
@cubap
Copy link
Copy Markdown
Member Author

cubap commented Jun 24, 2025

drafted until the rest of the stack is updated

…the-version-they-are-overwriting-has-changed
@cubap cubap marked this pull request as ready for review June 25, 2025 17:37
@cubap
Copy link
Copy Markdown
Member Author

cubap commented Jun 27, 2025

Ready for Review.

This considers incoming requests on the /overwrite path and reads the If-Overwritten-Version header or __rerum.isOverwritten value as a "version" of the document to be overwritten.

On a 409 error, the currentVersion should be passed back through with the error.

This change does not require any change to Services, Tiny, or Interfaces, but will never 409 until the downstream chain is in place. The one exception is that a user absentmindedly sending a complete object with a __rerum property may get a 409 instead of a 200 as they had been enjoying.

There is a PR that implements this in TinyPen, but not TinyThings yet.

Copy link
Copy Markdown
Member

@thehabes thehabes left a comment

Choose a reason for hiding this comment

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

The test files are just .txt files, but if they are something you want to have run you can try them as .js files. You could just leave them as TODO unless you want to save the notes.

Consider moving the check for __expectedVersion into __rerum

Comment thread db-controller.js Outdated
} catch (error) {
next(createExpressError(error))
// Optimistic locking check - no expected version is a brutal overwrite
const expectedVersion = req.get('If-Overwritten-Version') ?? req.body['__expectedVersion']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we check for this property in __rerum. That way we are not making __expectedVersion a reserve key on the payload body. What if I am legitimately trying to overwrite my object to be

{
  "name": "Bryan",
  "__expectedVersion": "good"
}

@thehabes thehabes merged commit de07b3f into main Jul 1, 2025
3 checks passed
@thehabes thehabes deleted the 197-overwrite-does-not-notify-requestors-if-the-version-they-are-overwriting-has-changed branch November 6, 2025 21:06
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.

Overwrite does not notify requestors if the version they are overwriting has changed.

2 participants