Skip to content

Conversation

@marcorudolphflex
Copy link
Contributor

@marcorudolphflex marcorudolphflex commented Feb 10, 2026

Refactors validator hotspots by consolidating multiple @model_validator(mode="after") hooks into a single orchestrator validator that invokes ordered helper methods. This preserves existing warning/error ordering and messages while improving readability and maintainability. Tests are added/updated to lock in validation order where needed.


Note

Medium Risk
Touches core model validation paths for mediums and simulations, so regressions could change warning/error timing or behavior even though the checks themselves are largely unchanged.

Overview
Refactors Pydantic v2 post-init validation for the Medium and Simulation class families by replacing many scattered @model_validator(mode="after") methods with a single _run_after_validators() orchestrator per class that calls helper checks in an explicit order.

Adds call_wrapped_validator(...) to invoke existing validator factories deterministically, updates several simulation variants (Simulation, ModeSimulation, EMESimulation, TCAD heat/charge) and multiple medium subclasses to follow the new pattern, and renames/privatizes various validator helpers for consistency.

Tests and policy enforcement: adds new tests to lock in validator warning/error ordering (e.g., CustomMedium, Simulation) and introduces test_validator_policy.py to prevent new mode="after" validators from being added outside _run_after_validators() in the medium/simulation hierarchies.

Written by Cursor Bugbot for commit ee771f8. This will update automatically on new commits. Configure here.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

Diff Coverage

Diff: origin/develop...HEAD, staged and unstaged changes

  • tidy3d/components/eme/simulation.py (100%)
  • tidy3d/components/medium.py (100%)
  • tidy3d/components/mode/simulation.py (100%)
  • tidy3d/components/simulation.py (100%)
  • tidy3d/components/tcad/simulation/heat_charge.py (100%)
  • tidy3d/components/validators.py (100%)

Summary

  • Total: 181 lines
  • Missing: 0 lines
  • Coverage: 100%

@marcorudolphflex marcorudolphflex force-pushed the FXC-5286-pydantic-v-2-refactor-validator-sprawl-in-simulation-medium-orchestrator-model-validator branch from 07ee26c to e86fd90 Compare February 10, 2026 10:17
@marcorudolphflex marcorudolphflex force-pushed the FXC-5286-pydantic-v-2-refactor-validator-sprawl-in-simulation-medium-orchestrator-model-validator branch from e86fd90 to c5b752a Compare February 10, 2026 10:41
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@marcorudolphflex marcorudolphflex force-pushed the FXC-5286-pydantic-v-2-refactor-validator-sprawl-in-simulation-medium-orchestrator-model-validator branch from c5b752a to 7fbc731 Compare February 10, 2026 14:00
@marcorudolphflex marcorudolphflex force-pushed the FXC-5286-pydantic-v-2-refactor-validator-sprawl-in-simulation-medium-orchestrator-model-validator branch from 7fbc731 to dbd7e5a Compare February 11, 2026 08:37
Copy link
Collaborator

@yaugenst-flex yaugenst-flex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcorudolphflex thanks, this looks good directionally. But as evidenced by this thread i think we need to improve the process design here too. At the very least there should be some docstrings, and also a contributor doc (could add this to AGENTS.md too) that documents the correct way to add validators in this style.

@marcorudolphflex marcorudolphflex force-pushed the FXC-5286-pydantic-v-2-refactor-validator-sprawl-in-simulation-medium-orchestrator-model-validator branch from dbd7e5a to 806c113 Compare February 11, 2026 10:41
@marcorudolphflex
Copy link
Contributor Author

@marcorudolphflex thanks, this looks good directionally. But as evidenced by this thread i think we need to improve the process design here too. At the very least there should be some docstrings, and also a contributor doc (could add this to AGENTS.md too) that documents the correct way to add validators in this style.

That makes definitely sense! Added some notes to Agents.md and docs/development/introduction/code_quality_principles.rst

@marcorudolphflex marcorudolphflex force-pushed the FXC-5286-pydantic-v-2-refactor-validator-sprawl-in-simulation-medium-orchestrator-model-validator branch from 57e250f to ee771f8 Compare February 11, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants