Repository navigation
fix(py/core): keep the declared config type on subclasses of EmbedRequest and ModelRequest - #272
Closed
pcbeingused33 wants to merge 1 commit into
Closed
pcbeingused33 wants to merge 1 commit into
pcbeingused33 wants to merge 1 commit into
Conversation
…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>
|
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. |
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.
Fixes #201
Cause.
declared_config_typeread__pydantic_generic_metadata__['args']of the class itself. A plain subclass such asclass CrmEmbedRequest(EmbedRequest[CrmEmbedConfig])has emptyargs(its parametrized base carries them), so it was treated as untyped:options/configwas emitted as a free-form object in the JSON schema, a foreignBaseModelinstance was accepted (and turned into a dict) instead of rejected, and an action annotated with the subclass got no inferredconfig_schema.Fix. Walk the MRO and use the first class that carries generic args. Bare
EmbedRequest,EmbedRequest[Any]and subclasses of them still resolve toNone, so the untyped behaviour is unchanged.Test. Extended
request_options_test.py: subclasses ofEmbedRequest[CrmEmbedConfig]andModelRequest[MenuModelConfig]report their config class, subclasses of bare /Anyrequests still reportNone, the subclass'soptionsschema 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.