Skip to content

Let FastAPI perform pydantic validation of EverestConfig objects - #14326

Open
berland wants to merge 2 commits into
equinor:mainfrom
berland:fastapi_everestconfig_validation
Open

Let FastAPI perform pydantic validation of EverestConfig objects#14326
berland wants to merge 2 commits into
equinor:mainfrom
berland:fastapi_everestconfig_validation

Conversation

@berland

@berland berland commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

The context (knowledge of installed forward model steps etc) is injected as a dependency to FastAPI.

The existing behaviour of muting all ConfigWarnings in the context-aware validation is continued in this commit. This assumes that both the client and the server is executed in an identical environment.

Issue
Resolves #13923

Approach
FastAPI dependencies with ExitStack

  • 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 screenshots are changed: Review screenshot-PR in ert-testdata,
    merge screenshot-PR in ert-testdata before merging this PR.
  • 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')

@berland berland self-assigned this Aug 31, 2026
@codecov-commenter

codecov-commenter commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.71429% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.65%. Comparing base (cc4cd2a) to head (88d2b2d).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
src/everest/detached/client.py 7.69% 12 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (cc4cd2a) and HEAD (88d2b2d). Click for more details.

HEAD has 10 uploads less than BASE
Flag BASE (cc4cd2a) HEAD (88d2b2d)
gui-tests 4 3
test 4 3
performance-and-unit-tests 4 0
cli-tests 4 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #14326       +/-   ##
===========================================
- Coverage   91.92%   70.65%   -21.28%     
===========================================
  Files         485      497       +12     
  Lines       33655    36084     +2429     
===========================================
- Hits        30939    25494     -5445     
- Misses       2716    10590     +7874     
Flag Coverage Δ
cli-tests ?
fuzz 43.84% <22.85%> (-0.53%) ⬇️
gui-tests 58.11% <11.42%> (-0.52%) ⬇️
performance-and-unit-tests ?
test 45.28% <65.71%> (-0.64%) ⬇️

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

Files with missing lines Coverage Δ
src/ert/base_model_context.py 100.00% <100.00%> (ø)
...rc/ert/dark_storage/endpoints/experiment_server.py 61.66% <100.00%> (+0.93%) ⬆️
src/everest/config/everest_config.py 94.46% <100.00%> (+0.01%) ⬆️
src/everest/config/simulator_config.py 100.00% <100.00%> (ø)
src/everest/detached/client.py 78.66% <7.69%> (-5.51%) ⬇️

... and 271 files with indirect coverage changes

The context (knowledge of installed forward model steps etc) is injected
as a dependency to FastAPI.

The existing behaviour of muting all ConfigWarnings in the context-aware
validation is continued in this commit. This assumes that both the
client and the server is executed in an identical environment.
@berland
berland force-pushed the fastapi_everestconfig_validation branch from 1f12f5c to bad4d8c Compare August 31, 2026 13:32
@codspeed-hq

codspeed-hq Bot commented Aug 31, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 36 untouched benchmarks


Comparing berland:fastapi_everestconfig_validation (88d2b2d) with main (112f2c8)

Open in CodSpeed

@router.post("/" + EverEndpoints.START_EXPERIMENT, dependencies=authenticated)
@router.post(
"/" + EverEndpoints.START_EXPERIMENT,
dependencies=[*authenticated, Depends(_with_runtime_plugins)],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we folow the pattern of authenticated = [Depends(verify_auth)] for Depends(_with_runtime_plugins) as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not sure it will add anything good, a little bit skeptical to the existing pattern of having a 1-member list for authenticated - I guess it can make sense in case this list can grow. I don't think the list of dependencies for runtime_plugins can grow.

retries: int = 5,
) -> str:
url, cert, auth = server_context
last_error: str | None = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we only want the last error message? Would it be better if we appended the messages?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think they are very likely to be identical. All error message can be found in the logs if needed.

Comment thread tests/everest/test_everserver.py Outdated
Comment on lines +378 to +381
monkeypatch.setenv("ERT_STORAGE_TOKEN", "password")
credentials = b64encode(b"username:password").decode()
auth_headers = {"Authorization": f"Basic {credentials}"}
client = TestClient(app)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that this is repeated a lot, could we add a fixture or method that generates it? e.g returns tuple of credentials, auth_headers and client?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added fixup commit

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.

Replace request by EverestConfig to let FastAPI handle Pydantic validation

3 participants