Skip to content

Fix crash when RESTART used without REFCASE/TIME_MAP - #14125

Draft
nirupam-06 wants to merge 1 commit into
equinor:mainfrom
nirupam-06:fix-convert-observations-missing-refcase
Draft

Fix crash when RESTART used without REFCASE/TIME_MAP#14125
nirupam-06 wants to merge 1 commit into
equinor:mainfrom
nirupam-06:fix-convert-observations-missing-refcase

Conversation

@nirupam-06

Copy link
Copy Markdown

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.

Issue
Fixes #14080

Approach
Added validation in _get_restart to check that time_map is non-empty and that the restart index falls within range before indexing into it, raising ObservationConfigError with 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).

  • 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')

`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 SAKavli left a comment

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 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():

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.

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():

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.

Same here.



@pytest.mark.usefixtures("use_tmpdir")
def test_that_restart_with_refcase_present_converts_successfully():

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.

  1. We try to avoid wording like "successfully", as that is too vague to understand what is being asserted.

  2. 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?

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.

convert_observations does not convert observations with restart with missing refcase

2 participants