Fix crash when RESTART used without REFCASE/TIME_MAP - #14125
Draft
nirupam-06 wants to merge 1 commit into
Draft
Conversation
`ert convert_observations` crashed with an unhandled IndexError when an observation used the RESTART keyword but the ERT config was missing both REFCASE and TIME_MAP. This happened because _get_restart assumed time_map would always be non-empty when computing a restart index, with no validation. Add explicit checks in _get_restart: raise a clear ObservationConfigError if time_map is empty, or if the given restart index falls outside the range of the time_map, instead of letting the code crash with an opaque IndexError. Also fix a pre-existing one-line indentation error in _legacy_handle_error_mode, caught by the ruff pre-commit hook while working in this file. Fixes equinor#14080
SAKavli
requested changes
Aug 10, 2026
SAKavli
left a comment
Contributor
There was a problem hiding this comment.
I see this is not ready for review, but as it looks close to ready, I thought I would drop you some comments already.
|
|
||
|
|
||
| @pytest.mark.usefixtures("use_tmpdir") | ||
| def test_that_restart_without_refcase_or_time_map_gives_clear_error(): |
Contributor
There was a problem hiding this comment.
We expect all errors to be clear, so it's enough to rename to e.g.:
test_that_restart_without_refcase_or_time_map_raises_obs_config_error
This will allow you to delete the redundant docstring, as it contains the same information as the title.
|
|
||
|
|
||
| @pytest.mark.usefixtures("use_tmpdir") | ||
| def test_that_restart_out_of_range_of_time_map_gives_clear_error(): |
|
|
||
|
|
||
| @pytest.mark.usefixtures("use_tmpdir") | ||
| def test_that_restart_with_refcase_present_converts_successfully(): |
Contributor
There was a problem hiding this comment.
-
We try to avoid wording like "successfully", as that is too vague to understand what is being asserted.
-
I want you to make sure this is not a redundant test. What is being tested here which is not already tested in the suite?
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.
ert convert_observationscrashed with an unhandled IndexError when an observation used the RESTART keyword but the ERT config was missing both REFCASE and TIME_MAP. This happened because _get_restart assumed time_map would always be non-empty when computing a restart index, with no validation.Add explicit checks in _get_restart: raise a clear ObservationConfigError if time_map is empty, or if the given restart index falls outside the range of the time_map, instead of letting the code crash with an opaque IndexError.
Also fix a pre-existing one-line indentation error in _legacy_handle_error_mode, caught by the ruff pre-commit hook while working in this file.
Issue
Fixes #14080
Approach
Added validation in
_get_restartto check thattime_mapis non-empty and that the restart index falls within range before indexing into it, raisingObservationConfigErrorwith a clear message instead of letting an IndexError propagate. Added three regression tests covering: RESTART without REFCASE/TIME_MAP, RESTART index out of range, and RESTART with a valid REFCASE present (success path, unaffected by the fix).git rebase -i main --exec 'just rapid-tests')When applicable
merge screenshot-PR in ert-testdata before merging this PR.