Fix voluptuous-openapi LazySchema unhashable type bug#96
Merged
balloob merged 1 commit intoJun 25, 2026
Merged
Conversation
f2112fb to
bedf19d
Compare
a167150 to
09023c1
Compare
09023c1 to
f256676
Compare
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.
Rationale
This PR addresses a
TypeError: cannot use 'voluptuous_openapi.LazySchema' as a dict keybug that occurs when converting voluptuous schemas containing references back to OpenAPI. It also introduces proper reference denormalization and cycle-breaking mechanisms during serialization.Proposed Changes
LazySchemaHashability: Implemented a__hash__method inLazySchemareturninghash(self.ref)to satisfy Python's hash contract while keeping the mutableroot_schemadictionary out of the hash calculation.convert()to check explicitly whether the callable is a class/routine or a custom callable instance (such asLazySchema), avoidingTypeErrorexceptions during type hint inspection.LazySchemaobjects back to OpenAPI, we now resolve and fully denormalize the target schema, rather than returning an incomplete/unresolvable{"$ref": ...}block without definitions._seen_refs: set[str]parameter toconvert()to track active recursion paths.{}(representingAny, which defaults to a string type viaensure_default), preventing infinite recursion.test_convert_schema_with_referenceto verify denormalization and validation of simple references.test_convert_schema_with_nested_referenceto verify denormalization two levels deep.test_convert_recursive_schemato verify cycle-breaking and recursion safety.test_convert_custom_callable_class_instanceto verify that custom callable class instances are converted robustly.