Repository navigation
fix(optimization): stop emitting required: true inside field schemas - #7517
Open
akashkokare2910 wants to merge 1 commit into
Open
akashkokare2910 wants to merge 1 commit into
akashkokare2910 wants to merge 1 commit into
Conversation
Pydantic v2 has no `required` argument on `Field`. It moved the value into `json_schema_extra`, which put `"required": true` inside each property's JSON schema. That is invalid JSON Schema, and it emitted `PydanticDeprecatedSince20` when the module was imported. The fields have no default, so they stay required. Drop the argument and the `type: ignore[call-overload]` comments that were hiding the type error.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
2. Or, if no issue exists, describe the change:
Problem:
Six fields in
optimization/data_types.pyandoptimization/local_eval_sampler.pyare declared asField(required=True, ...). Pydantic v2 has norequiredargument onField. It puts unknown keyword arguments intojson_schema_extraand emitsPydanticDeprecatedSince20when these modules are imported. The# type: ignore[call-overload]comments on those lines were hiding the mypy error.The leftover key ends up inside each property's JSON schema. That is invalid JSON Schema, which requires
requiredto be an array of names on the object:Solution:
Remove
required=Trueand the sixtype: ignore[call-overload]comments. The fields have no default, so Pydantic already treats them as required, and validation behavior does not change. The new tests check both points.Testing Plan
Unit Tests:
Added
tests/unittests/optimization/data_types_test.py:test_json_schema_marks_required_fields_at_object_level: fails onmainwith'required': Trueinside the property, and passes with this change.test_fields_without_default_are_required: confirms all six fields still fail validation when missing.Results:
pytest tests/unittests: 18452 passed, 87 skipped, 22 xfailed (before rebasing onto currentmain).pytest tests/unittests/optimization tests/unittests/evaluationafter rebasing: 1002 passed.mypyon both changed source files: no issues.pre-commit runon the changed files: all hooks pass.Manual End-to-End (E2E) Tests:
Not applicable. This change only affects schema generation. To check it by hand, run
SamplingResult.model_json_schema()andLocalEvalSamplerConfig.model_json_schema(): there is norequiredkey inside the properties, and the object-levelrequiredarray lists the fields. Importing both modules no longer emitsPydanticDeprecatedSince20.Checklist