Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engine: Catch NotImplementedErrorin get_process_state_change_timestamp #6489

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Jun 28, 2024

The get_process_state_change_timestamp utility calls the method get_global_variable on the storage backend to get the timestamp of the latest process state change, which is typically stored in the db_dbsetting table. However, not all storage plugins implement, most notably the core.sqlite_zip plugin. Since this is read-only, the settings table is never used and requesting the timestamp of the last process state change does not make sense.

Since this utility is used in verdi process list, the command would error since the NotImplementedError was not caught. This is now the case and verdi process list will show "never" as the last state change.

…tamp`

The `get_process_state_change_timestamp` utility calls the method
`get_global_variable` on the storage backend to get the timestamp of the
latest process state change, which is typically stored in the
`db_dbsetting` table. However, not all storage plugins implement, most
notably the `core.sqlite_zip` plugin. Since this is read-only, the
settings table is never used and requesting the timestamp of the last
process state change does not make sense.

Since this utility is used in `verdi process list`, the command would
error since the `NotImplementedError` was not caught. This is now the
case and `verdi process list` will show "never" as the last state change.
@sphuber sphuber force-pushed the fix/exception-get-process-state-change-timestamp branch from 71d3fd7 to 7966187 Compare June 28, 2024 11:37
Copy link

codecov bot commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 77.76%. Comparing base (ef60b66) to head (7966187).
Report is 115 commits behind head on main.

Files with missing lines Patch % Lines
src/aiida/engine/utils.py 83.34% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6489      +/-   ##
==========================================
+ Coverage   77.51%   77.76%   +0.26%     
==========================================
  Files         560      561       +1     
  Lines       41444    41800     +356     
==========================================
+ Hits        32120    32503     +383     
+ Misses       9324     9297      -27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sphuber sphuber requested a review from khsrali June 28, 2024 13:42
Comment on lines +319 to 327
try:
timestamp = backend.get_global_variable(key)
except NotImplementedError:
pass
else:
if timestamp is not None:
timestamps.append(datetime.fromisoformat(str(timestamp)))
except KeyError:
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

does the same ? :)

Suggested change
try:
timestamp = backend.get_global_variable(key)
except NotImplementedError:
pass
else:
if timestamp is not None:
timestamps.append(datetime.fromisoformat(str(timestamp)))
except KeyError:
continue
timestamp = backend.get_global_variable(key)
if timestamp is not None:
timestamps.append(datetime.fromisoformat(str(timestamp)))
except (KeyError, NotImplementedError) as exc:
continue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically yes, however, it is often better to wrap try/except statements around specific lines. This makes it clearer which statements could potentially throw which exception.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense ✅

@sphuber sphuber merged commit 04926fe into aiidateam:main Jun 29, 2024
11 checks passed
@sphuber sphuber deleted the fix/exception-get-process-state-change-timestamp branch June 29, 2024 07:20
mikibonacci pushed a commit to mikibonacci/aiida-core that referenced this pull request Sep 3, 2024
…tamp` (aiidateam#6489)

The `get_process_state_change_timestamp` utility calls the method
`get_global_variable` on the storage backend to get the timestamp of the
latest process state change, which is typically stored in the
`db_dbsetting` table. However, not all storage plugins implement, most
notably the `core.sqlite_zip` plugin. Since this is read-only, the
settings table is never used and requesting the timestamp of the last
process state change does not make sense.

Since this utility is used in `verdi process list`, the command would
error since the `NotImplementedError` was not caught. This is now the
case and `verdi process list` will show "never" as the last state change.
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.

2 participants