Skip to content

Comments

Narrower handling around unresolved refs#250

Merged
p1c2u merged 1 commit intomasterfrom
fix/narrower-handling-around-unresolved-refs
Feb 20, 2026
Merged

Narrower handling around unresolved refs#250
p1c2u merged 1 commit intomasterfrom
fix/narrower-handling-around-unresolved-refs

Conversation

@p1c2u
Copy link
Collaborator

@p1c2u p1c2u commented Feb 20, 2026

This pull request improves error handling in the handle_discriminator function and adds a new test to ensure correct behavior when unexpected reference errors occur. The main focus is on making sure only specific errors are caught and reported as validation errors, while others are properly propagated.

Error handling improvements:

  • Updated handle_discriminator in openapi_schema_validator/_keywords.py to catch _WrappedReferencingError and check if the underlying cause is Unresolvable, yielding a ValidationError only in that case; other exceptions are re-raised to avoid swallowing unexpected errors.
  • Added imports for _WrappedReferencingError and Unresolvable to support the improved error handling logic.

Testing enhancements:

  • Added a new test test_discriminator_does_not_swallow_unexpected_ref_errors in tests/integration/test_validators.py to verify that unexpected errors (like RuntimeError) in _validate_reference are not swallowed by the discriminator logic.
  • Imported Any and cast from typing to support monkeypatching in the new test.

@p1c2u p1c2u force-pushed the fix/narrower-handling-around-unresolved-refs branch from 10975a9 to e8e1c16 Compare February 20, 2026 17:51
@p1c2u p1c2u merged commit 0b4a1f2 into master Feb 20, 2026
14 checks passed
@p1c2u p1c2u deleted the fix/narrower-handling-around-unresolved-refs branch February 20, 2026 17:53
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.

1 participant