Repository navigation
test(py): pin EmbedRequest[Any] object schema for untyped embedder options - #6984
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the _untyped_options_schema function in _model.py to safely handle cases where the schema dictionary does not contain a 'properties' key by using setdefault('properties', {}). Additionally, a unit test has been added to verify this behavior and ensure missing properties are correctly populated. No review comments were provided, so there is no feedback to address.
hilariie
left a comment
There was a problem hiding this comment.
Is there a path where pydantic actually calls this hook without properties? Every model schema I tried (both modes, generics, subclasses, nested) already had it, so this reads as hardening rather than a KeyError fix.
1a6bb3f to
fe02b6e
Compare
|
checked reframed the PR title/body to |
Pins the JSON Schema contract for untyped embedder options (
EmbedRequest[Any]), ensuring plugin embedders that don't declare a config model still advertiseoptionsas a JSONobject({"type": "object", "additionalProperties": true}) to the Dev UI and reflection API rather than an unconstrainedanyschema.Context & Main Changes
_untyped_options_schemaonEmbedRequest/ModelRequestsoEmbedRequest[Any]advertises'type': 'object'instead ofany. This PR originally started as a defensiveschema.setdefault('properties', {})guard on that hook, but review (@hilariie,@cabljac) confirmed Pydantic'sGenerateJsonSchemaalways populates'properties'onBaseModelschemas—and uncovered that deleting_untyped_options_schemaaltogether left the entire test suite green because nothing testedEmbedRequest[Any]schema output.schema['properties']lookup: Revertedsetdefaultback toschema['properties']so any broken custom schema generator raisesKeyErrorloudly instead of emitting a malformed object schema, and updated_untyped_options_schema's docstring to nameEmbedRequest[Any]explicitly.EmbedRequestandEmbedRequest[Any]across both Pydantic schema modes: AddedTypeAdapter(...).json_schema(mode=...)assertions overEmbedRequestandEmbedRequest[Any]in both'validation'and'serialization'modes, plusdeclared_config_type(EmbedRequest[Any]) is None(follow-up subclass MRO tracking filed in fix(py): declared_config_type misses generic args on subclasses of EmbedRequest[T] and ModelRequest[T] genkit-python#201).