Repository navigation
fix: keep scalars in union deserialization instead of crashing - #1187
Chen Yufeiyang (feiiiiii5) wants to merge 2 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 877d2dd223
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| ], | ||
| ids=["str", "none", "dict", "dataclass"], | ||
| ) | ||
| def test_prompt_message_from_dict_deep_preserves_function_call(function_call, expected): |
There was a problem hiding this comment.
Move the regression tests into the collected core suite
Under the CI path in .github/workflows/checks.yaml, py/noxfile.py::_run_core_tests() supplies only src/braintrust as pytest's positional file_or_dir target (pytest --help: [file_or_dir] [file_or_dir] [...]); the separate sessions under tests/ target only tests/wheel and tests/api_codegen. This file is therefore never collected by CI or make test-core, so none of the six cases protects against reintroducing the prompt-deserialization crash. Move these cases into the existing py/src/braintrust/test_serializable_data_class.py, following root AGENTS.md's “colocated test_*.py” convention.
AGENTS.md reference: AGENTS.md:L57-L57
Useful? React with 👍 / 👎.
|
Addressed the Codex finding about test collection. The three regression tests were in |
Summary
SerializableDataClass.from_dict_deep()tried every dataclass member of a union wheneverv is not None, without checkingv's runtime type.PromptMessage.function_call: str | FunctionCall | Nonelegitimately accepts a string, butFunctionCall.from_dict_deep(str)called.items()and raisedAttributeError, which escaped theexcept TypeError. A saved/local prompt with a legacy stringfunction_calltherefore crashed parameter validation.Fix
Dispatch to a dataclass union member only when
vis aMapping; plain strings/scalars fall through to the existing assignment. Dict andNonebehavior is unchanged.Verification
test_parameters.pyand prompt cache tests): 67 passed.ruff checkandruff format --checkclean.No live
_create_prompt/API path, network, or credentials used.