fix(units): patch synonyms as item-level add/delete operations - #559
Merged
Conversation
Code ReviewIssues Found
Summary1 issue found. Low-severity — the fix logic is correct; the missing decorator is the only gap. |
m-j-hofmann
approved these changes
Jun 24, 2026
prasad-albert
commented
Jun 24, 2026
prasad-albert
left a comment
Collaborator
Author
There was a problem hiding this comment.
Unset synonyms will delete all existing synonyms
_generate_unit_patch_payload reads updated.synonyms or [] without checking model_fields_set. If a caller builds a partial update object without setting synonyms:
unit = Unit(id="x", symbol="y") # synonyms never set → not in model_fields_set
client.units.update(unit=unit)updated.synonyms or [] resolves to [], so existing_synonyms - [] emits a DELETE for every existing synonym. Same unset-vs-empty bug fixed in base.py / generate_adv_patch_payload in #561.
One-liner fix — add this right after stripping the old Synonyms datum:
payload.data = [d for d in payload.data if d.attribute != "Synonyms"]
if "synonyms" not in updated.model_fields_set:
return payload # caller never set synonyms → leave them untouchedExplicit synonyms=[] still lands in model_fields_set so intentional clears are preserved.
Partial update objects without synonyms in model_fields_set resolved to [] via 'or []', causing all existing synonyms to be deleted. Guard on model_fields_set before diffing, matching the pattern in base.py.
prasad-albert
force-pushed
the
fix/units-synonyms-patch
branch
from
June 24, 2026 09:44
eda8e6e to
73cbeca
Compare
prasad-albert
added a commit
that referenced
this pull request
Jun 25, 2026
The API rejects multiple operations on the same list attribute (e.g. Symbols) in a single request with '1 entities duplicated'. Batch scalar ops together and send each list-attribute op (delete/add) individually, matching the pattern used for Units/Synonyms in PR #559.
prasad-albert
added a commit
that referenced
this pull request
Jun 26, 2026
The API rejects multiple operations on the same list attribute (e.g. Symbols) in a single request with '1 entities duplicated'. Batch scalar ops together and send each list-attribute op (delete/add) individually, matching the pattern used for Units/Synonyms in PR #559.
This was referenced Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
synonymspreviously sent a single whole-listupdateop, which the backend rejects — it has noupdateoperation forSynonyms(only item-leveladd/delete, each with a scalar value), and it rejects more than one operation on the same attribute in a single request.synonymschanges are now diffed into per-itemadd/deleteoperations, and eachSynonymsoperation is sent as its own PATCH request (other attributes likesymbol/categorystill go in one request).test_unit_crud(no new fixture/seeding) — adds and removes a synonym and asserts the result. Verified end-to-end againstapp.albertinvent.com(fulltest_units.pysuite: 8 passed).