Skip to content

Fix idempotent writes and deletes: on_duplicate and on_missing should not be stored on ClientWriteRequest body#6

Closed
Copilot wants to merge 4 commits intofeat/support-write-conflict-optionsfrom
copilot/fix-idempotent-writes-deletes
Closed

Fix idempotent writes and deletes: on_duplicate and on_missing should not be stored on ClientWriteRequest body#6
Copilot wants to merge 4 commits intofeat/support-write-conflict-optionsfrom
copilot/fix-idempotent-writes-deletes

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 16, 2025

Fix idempotent writes and deletes handling for on_duplicate and on_missing

The issue was that on_duplicate and on_missing parameters were incorrectly stored on the ClientWriteRequest body when they should only be passed through options and set directly on the API model's writes/deletes objects.

Changes made:

  • Remove on_duplicate and on_missing from ClientWriteRequest.__init__ and their properties/setters
  • Update writes_tuple_keys and deletes_tuple_keys to be methods that accept these values as parameters
  • Update async client code (openfga_sdk/client/client.py) to pass conflict options when calling the methods
  • Update sync client code (openfga_sdk/sync/client/client.py) similarly
  • Remove the lines in client.py that incorrectly set these on the body
  • Fix default behavior to use API model defaults ("error") when no conflict option is provided
  • Update all test expectations to include default "on_duplicate": "error" and "on_missing": "error" values
  • All tests passing (175 tests pass)

Technical Details:

  • on_duplicate and on_missing are now passed as parameters to writes_tuple_keys() and deletes_tuple_keys() methods
  • The conflict options are extracted from the options dict and passed directly to these methods
  • When conflict options are not provided (None), the methods don't pass the parameter, allowing API models to use their defaults ("error")
  • This ensures the values are set on the API models (WriteRequestWrites/WriteRequestDeletes) not on the client body
  • The serialized output correctly places these options on the writes/deletes objects, not the top-level body
  • Test expectations updated to match the correct API body format with default values

Files Changed:

  • openfga_sdk/client/models/write_request.py - Core model changes
  • openfga_sdk/client/client.py - Async client updates
  • openfga_sdk/sync/client/client.py - Sync client updates
  • test/client/client_test.py - Test expectations updated
  • test/sync/client/client_test.py - Test expectations updated
Original prompt

openfga_sdk/client/models/write_request.py

line 32 self._on_duplicate = on_duplicate

These should not be here, these should be passed in the options

openfga_sdk/client/client.py
conflict_options = options_to_conflict_info(options)

    # Set conflict options on the body if provided
    if conflict_options:

Something is off here - nothing (neither the client model nor the API model should allow setting these on the body).

The client model, they're passed in the options - which is correct, they shouldn't be additionally added to the body.

For the API models, they should be a key on the writes/deletes

Can you address these it is related to idempotent writes and deletes on missing and on duplicate


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 16, 2025 17:50
…ed on body

Co-authored-by: SoulPancake <70265851+SoulPancake@users.noreply.github.com>
Co-authored-by: SoulPancake <70265851+SoulPancake@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix idempotent writes and deletes handling Fix idempotent writes and deletes: on_duplicate and on_missing should not be stored on ClientWriteRequest body Oct 16, 2025
Copilot AI requested a review from SoulPancake October 16, 2025 17:58
@SoulPancake
Copy link
Copy Markdown
Owner

@copilot The tests are failing now
Can you fix them all please thanks

…ing values

Co-authored-by: SoulPancake <70265851+SoulPancake@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Oct 16, 2025

@copilot The tests are failing now
Can you fix them all please thanks

Fixed all failing tests! The tests were expecting the API body to NOT include on_duplicate and on_missing when no conflict options were provided, but my changes correctly add the default values ("error") to the serialized API request. Updated all test expectations to include these defaults.

All 175 tests now pass ✅ (commit: 7dcc9b5)

@SoulPancake SoulPancake deleted the copilot/fix-idempotent-writes-deletes branch October 17, 2025 02:54
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