Skip to content

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

Open
erlenlh wants to merge 1 commit 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 1 commit 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 89.62%. Comparing base (7aa972d) to head (94eca0f).
⚠️ Report is 43 commits behind head on main.
✅ All tests successful. No failed tests found.

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     
Flag Coverage Δ
cli-tests 37.01% <100.00%> (-0.33%) ⬇️
fuzz 43.96% <100.00%> (-0.18%) ⬇️
gui-tests 63.70% <100.00%> (-3.09%) ⬇️
performance-and-unit-tests 78.03% <100.00%> (+0.06%) ⬆️
test 45.62% <100.00%> (-0.16%) ⬇️

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

Files with missing lines Coverage Δ
src/ert/config/derived_response_config.py 91.30% <100.00%> (-3.15%) ⬇️
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.76% <ø> (ø)
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/model_config.py 100.00% <100.00%> (ø)
src/ert/config/parameter_config.py 98.30% <100.00%> (ø)
src/ert/run_models/everest_run_model.py 92.08% <ø> (-0.02%) ⬇️

... and 71 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 2 times, most recently from 073d838 to dc3f340 Compare May 12, 2026 06:45
@erlenlh erlenlh force-pushed the ert-config-pydantic-base-model-update branch 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 on lines +786 to 787
class ErtConfig(BaseModel, extra="forbid"):
DEFAULT_ENSPATH: ClassVar[str] = "storage"
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