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

BaseRestartWorkChain: fix handler_overrides ignoring enabled=False #5598

Merged
merged 1 commit into from
Jul 14, 2022

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Jul 13, 2022

In commit 7b8c61d0869751455993891cfe5cf6c637593344, the input that
allows overriding handlers, handler_overrides, was updated to include
the possibility of overriding the priority. The changes broke the
original behavior though where a handler that was disabled by default
could not be enabled by specifying enabled=False in the overrides.

In commit `7b8c61d0869751455993891cfe5cf6c637593344`, the input that
allows overriding handlers, `handler_overrides`, was updated to include
the possibility of overriding the priority. The changes broke the
original behavior though where a handler that was disabled by default
could not be enabled by specifying `enabled=False` in the overrides.
@sphuber sphuber force-pushed the fix/base-restart-handler-overrides branch from 6261b8b to 7287434 Compare July 13, 2022 11:40
@sphuber sphuber requested a review from unkcpz July 13, 2022 11:40
Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

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

@sphuber thanks! Just a minor request for the clarity of the if-else statement. Otherwise, it is all good.

@@ -372,7 +372,7 @@ def get_process_handlers_by_priority(self) -> List[Tuple[int, FunctionType]]:
enabled = overrides.pop('enabled', None)
priority = overrides.pop('priority', None)

if enabled is False or not handler.enabled: # type: ignore[attr-defined]
if enabled is False or (enabled is None and not handler.enabled): # type: ignore[attr-defined]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if enabled is False or (enabled is None and not handler.enabled): # type: ignore[attr-defined]
if enabled and handler.enabled:
handlers.append((priority or handler.priority, handler))
else:
continue

Is this equal? If so it is more clear. But overall, this is hard to understand in which case the override is happening.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it is not equivalent, because imagine that handler.enabled is False, meaning the handler is disabled by default, and enabled is True, meaning the user is overriding it to be enabled, the conditional will evaluate to False, causing the handler to be skipped. But it should have been enabled.

What we are testing here is the if enabled is True in the overrides or it is not defined at all, but the default of the handler is that it is enabled, then it should be active.

I basically wrote it as the inverse, to know when to skip a handler, i.e., if the override is False or override is not specified and the default is False then the handler should not be active.

Not sure how to simplify this further. Maybe assigning intermediate variables would work?
I could write it perhaps as follows:

enabled_override = overrides.pop('enabled', None)
enabled_default = handler.enabled

if enabled_override is False or (enabled_override is None and enabled_default):
    continue

Does that help?

Copy link
Member

Choose a reason for hiding this comment

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

Variables with the specific name are more clear to me. I thought these two enable control two different things. It seems like override's enable control whether do override(I then realise this is meaningless).

Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

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

@sphuber thanks! Look it again, I think it is clear enough, maybe a comment is more helpful than changing the variable name? But overall is good to me.

@sphuber sphuber merged commit a0c0699 into aiidateam:main Jul 14, 2022
@sphuber sphuber deleted the fix/base-restart-handler-overrides branch July 14, 2022 15:47
@sphuber sphuber mentioned this pull request Jul 15, 2022
1 task
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.

None yet

2 participants