Skip to content

fix(py/core): keep the declared config type on subclasses of EmbedRequest and ModelRequest - #272

Closed
pcbeingused33 wants to merge 1 commit into
genkit-ai:mainfrom
pcbeingused33:fix/subclass-request-config-c7951
Closed

pcbeingused33 wants to merge 1 commit into
genkit-ai:mainfrom
pcbeingused33:fix/subclass-request-config-c7951

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Fixes #201

Cause. declared_config_type read __pydantic_generic_metadata__['args'] of the class itself. A plain subclass such as class CrmEmbedRequest(EmbedRequest[CrmEmbedConfig]) has empty args (its parametrized base carries them), so it was treated as untyped: options / config was emitted as a free-form object in the JSON schema, a foreign BaseModel instance was accepted (and turned into a dict) instead of rejected, and an action annotated with the subclass got no inferred config_schema.

Fix. Walk the MRO and use the first class that carries generic args. Bare EmbedRequest, EmbedRequest[Any] and subclasses of them still resolve to None, so the untyped behaviour is unchanged.

Test. Extended request_options_test.py: subclasses of EmbedRequest[CrmEmbedConfig] and ModelRequest[MenuModelConfig] report their config class, subclasses of bare / Any requests still report None, the subclass's options schema is a $ref, and a foreign config instance is rejected. Red on main, green with the change.


Disclosure: this change was prepared with AI assistance.

…uest and ModelRequest

declared_config_type only read the generic args of the class itself, so a
plain subclass of EmbedRequest[Cfg] / ModelRequest[Cfg] was treated as
untyped. Walk the MRO to find the parametrized base.

Fixes genkit-ai#201

Signed-off-by: Alex <alex.castillog33@gmail.com>
@genkit-bot

Copy link
Copy Markdown

Thanks for your interest in Genkit. We're closing this pull request because we can't accept it in its current form. If you'd like to contribute, please start a discussion with the maintainers on an issue first; see CONTRIBUTING.md.

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.

fix(py): declared_config_type misses generic args on subclasses of EmbedRequest[T] and ModelRequest[T]

3 participants