FXC-3378 Pydantic v2#2433
Conversation
0a529f4 to
a7e7a49
Compare
348a931 to
5ecc9f9
Compare
|
It seems like fundamentally there's just a few things that change? Maybe I'm missing something important/tricky. Could you explain if there's anything like that, and what changes going forward? Also very important - we will certainly need to update the backend python code too and might need to update denormalizer, metadata api, and who knows what else. |
|
Yes the biggest changes are related to custom types and serialization, everything else is relatively straightforward. I'll write something up. |
93ce359 to
dd10b26
Compare
dd0cd2b to
38d502a
Compare
ea3b4cb to
29234a6
Compare
6d3f88a to
2967f74
Compare
0a72b9c to
715c758
Compare
09d1e4a to
7e2c693
Compare
5000801 to
5dd22db
Compare
|
I have added a commit where all of the conflicts are resolved that can be resolved automatically. This is a bit tricky, because I had to make this a commit that does not resolve the other merge conflicts with some git magic (create two clones of the repo, make changes in one and copy them to the other as a "normal" commit). With the same strategy we should be able to bring this branch back on track piece by piece. In the end, we can squash all of these commits into a single rebase. @yaugenst-flex if this sounds good to you, I will continue to make more commits here that resolve more and more conflicts. For some of them I will need help though, because at first glance it does not always seem clear what the best strategy for merging is. |
|
we should also update the readme here: tidy3d/tidy3d/components/README.md Line 137 in d2bc9d4 with model_dump_json
|
daquinteroflex
left a comment
There was a problem hiding this comment.
Massive effort 🎉 💪
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
fix: rebase changes for v2 chore(tidy3d): FXC-4559-add-type-checking-import-moving-and-checking-to-pre-commit-and-ci fix: minor fixes for v2 fix: stabilize model hashing in tests fix: restore copy(True) compatibility and accept doping lists fix(tidy3d): FXC-4824-fix-corrupted-data-in-vtk-arrays fix: more rebase fixes for v2 fix(tidy3d): FXC-5094-fix-deprecation-warnings-in-tests fix: even more rebase changes final rebase changes fix: repair pydantic v2 validators chore: regenerate schemas chore(ci): fix move-type-imports and pin actions chore(ci): fix misleading python step name perf(pydantic): defer model build Fix missing Field reference in TCAD grid chore: remove stale pd references test: restore default pytest coverage docs: remove stale adjoint plugin warning Co-authored-by: Yannick Mahlau <yannik.mahlau@flexcompute.com> Co-authored-by: Marco Rudolph <marco.rudolph@flexcompute.com>
Summary
Migrates the tidy3d python client from Pydantic v1 → v2 across models, validators, serialization, and schema generation.
This PR also includes the CI/tooling updates needed to keep the v2 codebase clean (type-only import handling and mypy checks).
Key changes
Pydantic v2 migration
pydantic/pydantic_settings; remove v1 compatibility imports.@validator/@root_validatorwith@field_validator/@model_validator(incl.mode='before'|'after'|'wrap'where appropriate), updating signatures (ValidationInfo) and usingobject.__setattr__when mutatingfrozenmodels..dict()/.json()/.parse_obj()withmodel_dump*/model_validate, and.schema()withmodel_json_schema().model_config = ConfigDict(...).BaseSettingsusage topydantic_settings.BaseSettings.__get_pydantic_core_schema__/__get_pydantic_json_schema__Annotated[...]validators/serializers (BeforeValidator,PlainSerializer, etc.)schemas/.Pydantic-v2-specific fixes + regressions locked by tests
ValueMapvalidation bug caused byMapping.keys/valuesname collisions; add regression tests.__pydantic_*internals (guards future Pydantic bumps).Infinity/-Infinity/NaN(string-based, JSON-aligned); add regression test and document whyto_yaml()intentionally uses a JSON round-trip.info.data[...]cross-field access in field validators to avoidKeyErrorwhen prerequisite fields fail validation; add regression tests.Tooling / CI
Compatibility notes
tidy3d.exceptions.ValidationError,SetupError, etc.) for many validation failures; Pydantic core parse errors may differ slightly from v1 for invalid inputs.How to test
poetry run pre-commit run --all-filespoetry run pytest -qFollow-ups (post-merge)
Simulation/Mediuminto orchestrated helpers while preserving warning/error ordering.validation_alias/serialization_aliaswhere appropriate (may require schema review).Note
Medium Risk
Primarily CI/tooling and dependency constraint changes; moderate risk due to expanding mypy coverage to all of
tidy3dand introducing a new import-rewrite gate that could fail PRs or require code changes.Overview
Adds a new CI and pre-commit verification (
scripts/move_type_imports.py) that enforces type-only imports are moved underif TYPE_CHECKING, and wires this into the workflow’s required checks.Updates verification tooling to standardize on Python
3.11via a sharedVERIFICATIONS_PY_VERSION, adjustspytestconfig formatting, and broadensmypyto run across the fulltidy3dpackage.Tightens the Pydantic v2 dependency spec (
pydantic >=2.9,<3) and addspydantic-settings, plus includeslibcstin dev extras to support the new import-guard tooling; also ignoressimulation.jsonin git.Written by Cursor Bugbot for commit bdf3a7a. This will update automatically on new commits. Configure here.