fix(units): units_v4 family-ref aliases, legacy setup, merge wait - #784
Merged
Merged
Conversation
Units v4 endpoints serialize family references as {familyId, familyName}
but UnitFamilyV4Ref required id, so every convertible unit raised a
ValidationError on create/get/update/get_compatible and was silently
dropped from search pages. Accept both spellings via AliasChoices while
keeping serialization on the id/name keys.
Custom (Legacy) units carry no type until setup, so the required type field made them fail validation on read, and _generate_merge_patch never emitted type or the SI-mapping fields the setup flow needs. type is now optional on the model, and setting it on a legacy unit emits the setup payload (type plus ref_unit/ref_unit_exp for convertible, unit_families for non-convertible). Changing or clearing type after setup raises.
merge() returned as soon as the job was accepted with no way to track completion. A wait parameter now polls the job via poll_worker_job, the pattern used elsewhere in the SDK, raising on failure or timeout. The webhook_method parameter is typed Literal["POST", "GET"] to match the backend enum instead of an unvalidated str.
|
Code Review Issues Found
Summary |
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.
What
U1 RELEASE BLOCKER fixed (top priority): the units v4 endpoints serialize unit-family references as
{familyId, familyName}, butUnitFamilyV4Refrequiredid, socreate/get_by_id/get_by_ids/update/get_compatibleraisedValidationErroron every convertible unit andsearchsilently dropped them via the paginator's per-item fallback.Audit §5.40 findings addressed (units v4 vs invent-core
services/master-data):UnitFamilyV4Refaccepts both wire spellings viavalidation_alias=AliasChoices("id", "familyId")/AliasChoices("name", "familyName"). Serialization stays on theid/namekeys, so SDK request payloads are unchanged.merge()gainedwait: bool = False; withwait=Trueit polls the returned job via the existingpoll_worker_jobhelper (the pattern used by tasks), raising on failure or timeout.UnitV4.typeis now optional (legacy units carry notypeuntil setup and previously failed validation on read), andupdate()emits the setup payload:typeplusrefUnit/refUnitExp/refUnitValuefor a convertible setup orunitFamiliesfor a non-convertible one. Changing or clearingtypeafter setup raises client-side.merge(webhook_method=…)is nowLiteral["POST", "GET"], matching the backendWebhookMethodenum (was an unvalidatedstr).Why
SDK-168. Verified against invent-core
integrationbranch:unit-family-ref.dto.ts(familyId/familyName),unit.dto.ts+unit-search-item.dto.ts(same ref shape on GET/search),units.service.tsdispatchUpdate/executeSetupPath(setup triggers on a Custom (Legacy) record with no type when the patch carriestype), andmerge-unit.dto.ts(webhookPOST/GETenum +@IsUrl).How
{id, name}shape to the real{familyId, familyName}shape, plus a pin that both spellings validate and serialization is stable._generate_merge_patch: atypechange is only legal when the existing unit has none (legacy), and the family-change gate now evaluates the effective (post-setup) type.wait=Truecallspoll_worker_job(session=…, job_id=…)before returning the job id; default behavior is unchanged.Testing
ruff format --check .+ruff check .: clean (398 files).pytest tests/unit tests/test_exceptions.py: 73 passed, including new merge-patch tests for both legacy setup paths and post-setup type-change guards, and alias-tolerance pins.pytest tests/collections/test_units_v4.py tests/collections/test_unit_families_v4.py tests/collections/test_units.py --collect-only: 22 collected. Integration suites remain skip-marked (units v4 API not yet in the test environment) and no integration credentials were available, so they were not run.Not in this PR
main'sexceptions.pystill maps only 400/401/403/404/500/502, so these are landing via SDK-170 (in progress on another branch); noted here as a dependency rather than duplicated.Cake session: https://agents.ai.albertinventdev.com/sessions/910a4725-9404-4336-81dd-e30bfef0ce73