Skip to content

Add extra=forbid to pydantic basemodels in ert config and cleanup#13501

Open
erlenlh wants to merge 2 commits into
mainfrom
ert-config-pydantic-base-model-update
Open

Add extra=forbid to pydantic basemodels in ert config and cleanup#13501
erlenlh wants to merge 2 commits into
mainfrom
ert-config-pydantic-base-model-update

Conversation

@erlenlh
Copy link
Copy Markdown
Contributor

@erlenlh erlenlh commented May 7, 2026

Issue
Resolves #13498

Approach
Short description of the approach

(Screenshot of new behavior in GUI if applicable)

  • PR title captures the intent of the changes, and is fitting for release notes.
  • Added appropriate release note label
  • Commit history is consistent and clean, in line with the contribution guidelines.
  • Make sure unit tests pass locally after every commit (git rebase -i main --exec 'just rapid-tests')

When applicable

  • When there are user facing changes: Updated documentation
  • New behavior or changes to existing untested code: Ensured that unit tests are added (See Ground Rules).
  • Large PR: Prepare changes in small commits for more convenient review
  • Bug fix: Add regression test for the bug
  • Bug fix: Add backport label to latest release (format: 'backport release-branch-name')

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.09%. Comparing base (a139c58) to head (eaaa544).
⚠️ Report is 22 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13501      +/-   ##
==========================================
+ Coverage   89.37%   90.09%   +0.72%     
==========================================
  Files         469      468       -1     
  Lines       33391    33408      +17     
==========================================
+ Hits        29843    30100     +257     
+ Misses       3548     3308     -240     
Flag Coverage Δ
cli-tests 35.79% <100.00%> (+0.03%) ⬆️
fuzz 43.38% <100.00%> (-0.06%) ⬇️
gui-tests 59.27% <100.00%> (-0.07%) ⬇️
performance-and-unit-tests 77.82% <100.00%> (-0.01%) ⬇️
test 46.07% <100.00%> (+1.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/ert/config/distribution.py 99.11% <100.00%> (-0.01%) ⬇️
src/ert/config/ensemble_config.py 97.08% <100.00%> (ø)
src/ert/config/ert_config.py 95.80% <100.00%> (ø)
src/ert/config/everest_control.py 87.50% <100.00%> (-0.16%) ⬇️
src/ert/config/forward_model_step.py 98.66% <100.00%> (ø)
src/ert/config/gen_data_config.py 95.57% <ø> (ø)
src/ert/config/model_config.py 100.00% <100.00%> (ø)
src/ert/config/parameter_config.py 98.41% <100.00%> (ø)
src/ert/config/response_config.py 97.87% <100.00%> (ø)
src/ert/config/summary_config.py 96.42% <ø> (ø)
... and 1 more

... and 18 files with indirect coverage changes

@erlenlh erlenlh force-pushed the ert-config-pydantic-base-model-update branch from 342a64c to cd3b1b2 Compare May 7, 2026 08:35
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 7, 2026

Merging this PR will not alter performance

✅ 36 untouched benchmarks


Comparing ert-config-pydantic-base-model-update (94eca0f) with main (fab64f3)

Open in CodSpeed

@erlenlh erlenlh force-pushed the ert-config-pydantic-base-model-update branch 3 times, most recently from dc3f340 to 94eca0f Compare May 12, 2026 08:36
@erlenlh erlenlh requested a review from Copilot May 28, 2026 11:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-level extra="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_name is captured as eclbase above, but it is no longer propagated into runpath_config (now via summary_file_base_name). This means .res_runpath_list and 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 setting summary_file_base_name on ErtModelConfig when summary_fm is 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 thread src/ert/config/ert_config.py
# Conflicts:
#	src/ert/config/derived_response_config.py
@erlenlh erlenlh force-pushed the ert-config-pydantic-base-model-update branch from 94eca0f to 3fd3a0f Compare June 4, 2026 08:26
@erlenlh erlenlh force-pushed the ert-config-pydantic-base-model-update branch from 3fd3a0f to eaaa544 Compare June 4, 2026 11:01
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.

Ert config BaseModel extra=forbid

3 participants