Add extra=forbid to pydantic basemodels in ert config and cleanup#13501
Open
erlenlh wants to merge 1 commit into
Open
Add extra=forbid to pydantic basemodels in ert config and cleanup#13501erlenlh wants to merge 1 commit into
erlenlh wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13501 +/- ##
==========================================
- Coverage 89.95% 89.62% -0.34%
==========================================
Files 459 460 +1
Lines 32173 32516 +343
==========================================
+ Hits 28942 29143 +201
- Misses 3231 3373 +142
Flags with carried forward coverage won't be shown. Click here to find out more.
|
342a64c to
cd3b1b2
Compare
073d838 to
dc3f340
Compare
dc3f340 to
94eca0f
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens ERT configuration validation by setting several Pydantic BaseModel-based config classes to extra="forbid", preventing silent acceptance of unknown fields and cleaning up affected call sites/tests.
Changes:
- Enforce
extra="forbid"on multiple ERT config models (e.g.,ErtConfig,ModelConfig,EnsembleConfig,ParameterConfig, etc.). - Remove now-invalid “extra” constructor fields from unit tests and strategies (e.g.,
random_seed,eclbase_format_string,nx/ny/nz,mask_file). - Simplify some config model definitions by replacing
model_config = ConfigDict(extra="forbid")with class-levelextra="forbid".
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ert/unit_tests/run_models/test_model_factory.py | Removes now-forbidden extra ctor arg (random_seed) when building ErtConfig in tests. |
| tests/ert/unit_tests/run_models/test_experiment_serialization.py | Updates Hypothesis strategies to stop passing forbidden extra fields into config models. |
| tests/ert/unit_tests/config/test_field.py | Removes mask_file from Field(...) construction in test helper. |
| src/ert/run_models/everest_run_model.py | Updates Everest → ERT runpath config creation to align with config model field changes. |
| src/ert/config/parameter_config.py | Sets ParameterConfig to forbid extra fields. |
| src/ert/config/model_config.py | Sets ModelConfig to forbid extra fields. |
| src/ert/config/forward_model_step.py | Sets ForwardModelStepDocumentation to forbid extra fields. |
| src/ert/config/everest_control.py | Sets SamplerConfig to forbid extra fields; removes redundant ConfigDict usage/import. |
| src/ert/config/ert_config.py | Sets ErtConfig to forbid extra fields. |
| src/ert/config/ensemble_config.py | Sets EnsembleConfig to forbid extra fields. |
| src/ert/config/distribution.py | Converts model_config = {"extra": "forbid"} to class-level extra="forbid". |
| src/ert/config/derived_response_config.py | Sets DerivedResponseConfig to forbid extra fields. |
Comments suppressed due to low confidence (1)
src/ert/run_models/everest_run_model.py:340
summary_fm.results.file_nameis captured aseclbaseabove, but it is no longer propagated intorunpath_config(now viasummary_file_base_name). This means.res_runpath_listand the<ECLBASE>/<ECL_BASE>substitutions fall back to defaults even when the Everest config specifies a summary base name, which can break workflows expecting the runpath list to contain the simulator case base and can desynchronize simulator output naming vs response reading. Consider settingsummary_file_base_nameonErtModelConfigwhensummary_fmis present (and/or ensuring it matches the SummaryConfig input base).
runpath_config = ErtModelConfig(
num_realizations=len(everest_config.model.realizations)
if everest_config.model.realizations is not None
else 1,
runpath_format_string=str(
Comment on lines
99
to
102
| forward_init_file="no_nees", | ||
| output_file="no_nees", | ||
| grid_file="no_nees", | ||
| mask_file=Path("grid_mask.npy"), | ||
| ) |
Comment on lines
+786
to
787
| class ErtConfig(BaseModel, extra="forbid"): | ||
| DEFAULT_ENSPATH: ClassVar[str] = "storage" |
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.
Issue
Resolves #13498
Approach
Short description of the approach
(Screenshot of new behavior in GUI if applicable)
git rebase -i main --exec 'just rapid-tests')When applicable