fix: tolerate unknown enum values on deserialization (#203, #205, #206)#231
Open
CedricConday wants to merge 1 commit into
Open
fix: tolerate unknown enum values on deserialization (#203, #205, #206)#231CedricConday wants to merge 1 commit into
CedricConday wants to merge 1 commit into
Conversation
…roAPI#205, XeroAPI#206) The Xero API can return enum values this generated SDK predates (e.g. tax_number_type='TAXNUMBERTYPE/SSN', source_transaction_type_code='RECEIPT'). The per-attribute setters reject those with ValueError, which crashes deserialization of an otherwise-valid response and forces callers to monkey-patch the SDK. deserialize_model now falls back to building the model tolerantly, preserving the raw value the API sent. Valid values are unaffected. Adds a regression test.
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.
Fixes #203, #205, #206.
The Xero API returns enum values this generated SDK predates — e.g. a contact with
TaxNumberType="TAXNUMBERTYPE/SSN"(#203, #205) or a linked transaction withSourceTransactionTypeCode="RECEIPT"(#206). The per-attribute setters validate against a hardcodedallowed_valuesand raiseValueError, which crashes deserialization of an otherwise-valid API response and forces callers to monkey-patch the SDK.deserialize_modelnow attempts the normal validating construction first — so all valid data behaves exactly as before — and only onValueErrorfalls back to building the model tolerantly, preserving the raw value the API sent (set on the private field, bypassing the setter). Deserialization shouldn't reject values the authoritative server returns.Verified locally: both reported values reproduce the
ValueErroronmainand deserialize cleanly after; valid values (e.g.EIN) are unaffected. Addedtest_deserialize_model_tolerates_unknown_enum; full deserializer suite green (63 passed).🤖 Generated with Claude Code