Skip to content

Extend plugin_executor to catch warnings during msg construction and …#104

Open
robertplatt-mo wants to merge 3 commits intoMetOffice:mainfrom
robertplatt-mo:catch_and_extend_msg_construction_warnings_in_plugin_executor
Open

Extend plugin_executor to catch warnings during msg construction and …#104
robertplatt-mo wants to merge 3 commits intoMetOffice:mainfrom
robertplatt-mo:catch_and_extend_msg_construction_warnings_in_plugin_executor

Conversation

@robertplatt-mo
Copy link
Copy Markdown

…append the plugin filepath to the warning message.

@robertplatt-mo robertplatt-mo marked this pull request as draft February 23, 2026 13:02
@robertplatt-mo robertplatt-mo force-pushed the catch_and_extend_msg_construction_warnings_in_plugin_executor branch from ac6e008 to 2103a45 Compare February 27, 2026 10:47
@robertplatt-mo robertplatt-mo force-pushed the catch_and_extend_msg_construction_warnings_in_plugin_executor branch 2 times, most recently from 1fb0c03 to 09daad6 Compare February 27, 2026 11:44
@robertplatt-mo robertplatt-mo force-pushed the catch_and_extend_msg_construction_warnings_in_plugin_executor branch from 9844df5 to 47673b2 Compare February 27, 2026 12:08
@robertplatt-mo
Copy link
Copy Markdown
Author

Carwyn Pelley (@cpelley) In order to get the CI to run I had to make changes to how the code is checked out for forks. I'm not expecting this to be merged I just wanted the CI to run. The change to the docs could feasibly me merged as it just ensures that when we push from a fork we skip the task that pushes the documentation.

I know I need to add my name to contributors but I figured I'd let you feedback first.

- name: Commit and push documentation changes
if: steps.check-docs.outputs.changed == 'true'

if: ${{ steps.check-docs.outputs.changed == 'true' && !github.event.pull_request.head.repo.fork }}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Apologies for this. I updated the repository to require forks without consideration of the its impact to the actions.
Let's go with your changes to the workflow for now -- I'll put on my todo to update the actions to properly work with forks 👍

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi. Sorry I've been on leave. I'm actually not sure what the request is here. Do you mean we should keep my changes to workflows/tests.yml for now? If so what are next steps?

Copy link
Copy Markdown
Collaborator

@cpelley Carwyn Pelley (cpelley) left a comment

Choose a reason for hiding this comment

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

I don't think this branch is currently doing what you think it is doing since the context manager isn't around the actual execution. It could do with a more integration test that demonstrates it working.


msg = f"{obj_name}{call_msg}(*{args}, **{callable_kwargs})"
obj_path = get_object_path(callable_obj)
with warnings.catch_warnings(record=True) as caught_warnings:
Copy link
Copy Markdown
Collaborator

@cpelley Carwyn Pelley (cpelley) Apr 16, 2026

Choose a reason for hiding this comment

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

This context manager isn't around the execution of the application itself (only the definition of a string) so isn't actually doing anything currently.

msg = f"{obj_name}{call_msg}(*{args}, **{callable_kwargs})"
for warning in caught_warnings:
warnings.warn(
message=f"[Plugin: {obj_path}] | {warning.message}",
Copy link
Copy Markdown
Collaborator

@cpelley Carwyn Pelley (cpelley) Apr 16, 2026

Choose a reason for hiding this comment

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

Following precedence of the extra context we provide to exception messages raised by applications executed, we should provide similar context to the conditions which led to warning -- object name (application) and the parameters we provided it. This helps users determine the circumstances that resulted in this warning.

return nxgraph


def get_object_path(obj):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should likely not live inside this same module.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I have addressed issues with this workflow file for running from forks now.

Comment on lines +12 to +22
def test_func(): ...


class TestClass: ...


TEST_INSTANCE = TestClass()
TEST_LAMBDA = lambda: None
TEST_STRING = os.path.abspath(__file__)

TEST_CASES = [test_func, TestClass, TEST_INSTANCE, TEST_LAMBDA, TEST_STRING]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some/all of these will be picked up as tests in the pytest test discover due to naming. Use of 'Dummy' or similar would avoid this.

@cpelley
Copy link
Copy Markdown
Collaborator

robertplatt-mo, Joshua Wiggs (@JoshuaWiggs) — thanks for the work on this. I don’t currently see how the PR, in its present form, is able to function as intended (see comments above).
I’m also not yet clear on how this fits into DAGrunner’s overall logging and monitoring approach. While tagging warning messages with the application path does seem useful, I would have expected, consistent with the previous exception-handling behaviour, that the arguments passed to the science application which triggered the warning would also be included, for example, see

except Exception as err:
msg = (
f"Failed to execute {obj_name} with {args}, {callable_kwargs}"
f"\nnode_properties: {node_properties}"
f"\nnode_id: {node_id}"
)
raise RuntimeError(msg) from err

Additionally, this change likely needs some consideration in the broader context of DAGrunner’s logging and monitoring framework.
As there is currently no context provided in the PR description, my understanding is that the aim is to make it easier to identify which improver/epp application was running when underlying libraries (e.g. Iris or NumPy) emit a warning in order to better differentiate between known warnings and unknown warnings. If that is the case, it may be worth considering whether a straightforward change in epp itself would better address this need in the short term. I’m very happy to discuss ideas or suggestions, but I think some further thought is needed on how best to integrate this kind of behaviour into DAGrunner.

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