Skip to content

fix: restore sibling errors on union branch success (Python, PHP)#161

Merged
clemensv merged 1 commit into
masterfrom
fix/issue-160-union-sibling-errors
Jun 4, 2026
Merged

fix: restore sibling errors on union branch success (Python, PHP)#161
clemensv merged 1 commit into
masterfrom
fix/issue-160-union-sibling-errors

Conversation

@clemensv
Copy link
Copy Markdown
Contributor

@clemensv clemensv commented Jun 4, 2026

Summary

Fixes #160InstanceValidator union-type branch wiped accumulated sibling errors when a union member validated successfully.

Root Cause

In both the Python and PHP implementations, the union validation loop set self.errors = [] before trying each branch type. On a successful branch match, the code broke out of the loop without restoring the backup, leaving the error list empty and discarding all previously collected violations for sibling properties.

Fix

Always capture branch errors in a local variable and restore the backup before checking success — both on match and non-match paths. This ensures sibling errors are preserved regardless of union validation outcome.

Other SDKs

Checked all 11 SDK implementations:

  • Rust, Go, TypeScript, Swift — already correct (use separate temp result/context)
  • C, Perl — use simple type-match functions without shared error accumulation
  • Java, C# — don't handle type unions at the instance validation level

Tests

Added regression tests in both Python and PHP covering the exact reproducer from the issue (object with failing int64 siblings + succeeding ["double", "null"] union property).

InstanceValidator union-type branch wiped accumulated sibling errors
when a union member validated successfully. The code broke out of the
loop without restoring self.errors/this->errors from backup, leaving
the error list empty and discarding all previously collected violations.

Always capture branch errors in a local variable and restore the backup
before checking success, both on the match and non-match paths.

Fixes #160
@clemensv clemensv merged commit 9da9b0e into master Jun 4, 2026
11 checks passed
@clemensv clemensv deleted the fix/issue-160-union-sibling-errors branch June 4, 2026 10:12
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.

InstanceValidator union branch wipes accumulated sibling errors on successful match (order-dependent under-reporting)

1 participant