fix(unchecked_base_model): handle bare dict in construct_type#775
Open
devteamaegis wants to merge 1 commit into
Open
fix(unchecked_base_model): handle bare dict in construct_type#775devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
When type_ is a bare unparameterized dict, get_args(dict) returns () causing ValueError on tuple unpacking. Fall back to (Any, Any) when no args are present.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit e6db0dd. Configure here.
| @@ -0,0 +1,11 @@ | |||
| import sys | |||
| import os | |||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src")) | |||
There was a problem hiding this comment.
Unnecessary sys.path hack inconsistent with other tests
Low Severity
The sys.path.insert hack is inconsistent with every other test file in this project, which all import cohere directly without path manipulation. The project uses pyproject.toml with packages = [{ include = "cohere", from = "src"}] and expects the package to be installed in the environment (via poetry install or equivalent). This workaround bypasses that and could cause subtle import-ordering issues if the installed package and source tree ever diverge.
Reviewed by Cursor Bugbot for commit e6db0dd. Configure here.
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.


What's broken
Calling
construct_type(type_=dict, object_={...})raisesValueError: not enough values to unpack (expected 2, got 0). Any Pydantic model field annotated as baredict(rather thanDict[str, Any]) triggers this crash during deserialization.Why it happens
get_args(dict)returns an empty tuple, so the two-target unpackingkey_type, items_type = get_args(type_)fails when no type parameters are present.Fix
Replace the bare unpacking with
args = get_args(type_); key_type, items_type = args if args else (typing.Any, typing.Any). This makes a baredictbehave identically toDict[Any, Any].Test
Added
tests/test_unchecked_base_model.py::test_construct_type_bare_dict_no_unpack_errorwhich callsconstruct_typewithtype_=dictand asserts the result equals the input dict without raising.Fixes #774
Note
Low Risk
Small defensive change in deserialization coercion plus a unit test; no auth, security, or API contract changes.
Overview
Fixes a crash in
construct_typewhen the declared type is an unparameterizeddict.get_args(dict)is empty, so unpacking into key/value element types raisedValueErrorduring model construction/deserialization for fields typed as baredict.The change reads type parameters from
get_argsand, when none are present, treats the mapping asDict[Any, Any](keys and values passed throughconstruct_typewithout failing). A regression test assertsconstruct_type(type_=dict, object_={...})returns the input mapping unchanged.Reviewed by Cursor Bugbot for commit e6db0dd. Bugbot is set up for automated code reviews on this repo. Configure here.