Skip to content

side effects of failed modification#1452

Open
omursahin wants to merge 3 commits intomasterfrom
oracle-failed-modification
Open

side effects of failed modification#1452
omursahin wants to merge 3 commits intomasterfrom
oracle-failed-modification

Conversation

@omursahin
Copy link
Collaborator

No description provided.

@omursahin omursahin requested a review from arcuri82 February 19, 2026 11:54
}

// otherwise compare entire bodies
return bodyBefore != bodyAfter
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we should return a false here, as otherwise too prone to false positives due to non-deterministic fields

/**
* Compare only the fields that were sent in the PUT/PATCH request.
* Returns true if any of those fields changed between before and after GET responses.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

add comment stating this only works where the payload is a JSON object matching the resource structure. it will not work for cases like JSON Patch RFC6902

internal fun hasChangedModifiedFields(
bodyBefore: String,
bodyAfter: String,
fieldNames: Set<String>
Copy link
Collaborator

Choose a reason for hiding this comment

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

to avoid flakiness, i think we should pass as well the bodyModify, and do check on that


if(!jsonBefore.isJsonObject || !jsonAfter.isJsonObject){
// not JSON objects, fallback to full comparison
return bodyBefore != bodyAfter
Copy link
Collaborator

Choose a reason for hiding this comment

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

return false. see previous explanations

val valueAfter = objAfter.get(field)

if(valueBefore != valueAfter){
return true
Copy link
Collaborator

Choose a reason for hiding this comment

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

besides being different from valueBefore, we should make sure that valueAfter is equal to valueModify

return false
} catch (e: Exception) {
// JSON parsing failed, fallback to full comparison
return bodyBefore != bodyAfter
Copy link
Collaborator

Choose a reason for hiding this comment

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

return false


/**
* Checking bugs like:
* POST|PUT /X 2xx (create resource)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this first call is not strictly necessary. resources could be already existing or created with database insertions

*
* If a PUT/PATCH fails with 4xx, it should have no side-effects.
* A GET before and after should return the same resource state.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

add to comment that we need to take into account the non-determinism of the fields, eg like timestamps and UUIDs

return@forEach
}

// among those, find one that also has a successful creation step
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks. after reading this code i realized there are quite a few edge cases we need to handle. code here needs to be changed. i update the algorithm description in notes.txt

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.

2 participants