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

Fixes __context for classed based actions #449

Merged
merged 1 commit into from
Dec 4, 2024
Merged

Conversation

skrawcz
Copy link
Contributor

@skrawcz skrawcz commented Dec 3, 2024

  1. Python name mangles __variables on methods.
  2. We need to account for that for things to work and inject it properly.

We don't modify the inputs dict since we don't want to change anything, so we shallow copy it, and change the single key value.

Updates docs and adds example to show people.

Changes

  • tweak to running class based actions
  • docs
  • test

How I tested this

  • locally via example
  • via unit tests

Notes

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

Important

Fixes handling of __context in class-based actions by remapping mangled variable names and updates documentation and tests accordingly.

  • Behavior:
    • Adds _remap_context_variable() in application.py to handle name mangling of __context in class-based actions.
    • Updates _run_function() in application.py to use _remap_context_variable() when __context is in inputs.
  • Documentation:
    • Updates actions.rst to include examples of using __context in class-based actions.
    • Adds application_classbased.py as an example of class-based actions using __context.
  • Tests:
    • Adds tests for _remap_context_variable() in test_application.py to verify correct remapping of __context.
    • Adds test_application.py to test class-based action behavior with __context.
  • Misc:
    • Updates README.md in hello-world-counter to reference application_classbased.py for class-based action examples.

This description was created by Ellipsis for 5a36d46. It will automatically update as commits are pushed.

1. Python name mangles __variables on methods.
2. We need to account for that for things to work and inject it properly.

We don't modify the inputs dict since we don't want to change anything,
so we shallow copy it, and change the single key value.

Updates docs and adds example to show people.
@skrawcz skrawcz requested a review from elijahbenizzy December 3, 2024 20:16
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to 5a36d46 in 59 seconds

More details
  • Looked at 342 lines of code in 6 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. burr/core/application.py:146
  • Draft comment:
    The current implementation of _remap_context_variable only checks for parameters ending with __context. Consider checking for the presence of __context in the parameter name to handle different mangling scenarios more robustly.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The function _remap_context_variable is designed to handle the mangling of the __context variable in class-based actions. However, the current implementation only checks for parameters ending with __context, which might not be sufficient if the mangled name is different. A more robust approach would be to check for the presence of __context in the parameter name, regardless of its position.

Workflow ID: wflow_QaOryZCeOL5RlgpY


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

github-actions bot commented Dec 3, 2024

A preview of is uploaded and can be seen here:

https://burr.dagworks.io/pull/449

Changes may take a few minutes to propagate. Since this is a preview of production, content with draft: true will not be rendered. The source is here: https://github.com/DAGWorks-Inc/burr/tree/gh-pages/pull/449/

Copy link
Contributor

@elijahbenizzy elijahbenizzy left a comment

Choose a reason for hiding this comment

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

Edit -- I think there's a more upstream way to do this, but digging in

@@ -103,6 +103,31 @@ def _adjust_single_step_output(
_raise_fn_return_validation_error(output, action_name)


def _remap_context_variable(run_method: Callable, inputs: Dict[str, Any]) -> dict:
Copy link
Contributor

Choose a reason for hiding this comment

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

We should do this with any __ variable... __tracer will hit the same problem. Could hardcode this, but we should consider being more aware of the context.

@@ -121,6 +146,9 @@ def _run_function(function: Function, state: State, inputs: Dict[str, Any], name
)
state_to_use = state.subset(*function.reads)
function.validate_inputs(inputs)
if "__context" in inputs:
# potentially need to remap the __context variable
inputs = _remap_context_variable(function.run, inputs)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think remapping the context variable should be aware of the signature of the run function. Who knows how it would be created...

Rather, let's just hardcode the name-mangled version and unmangle them? Or maybe do it upstream?

@skrawcz
Copy link
Contributor Author

skrawcz commented Dec 4, 2024

will handle __tracer later in another commit/PR.

@elijahbenizzy elijahbenizzy merged commit 2bfe88b into main Dec 4, 2024
11 checks passed
@elijahbenizzy elijahbenizzy deleted the fix_class_context branch December 4, 2024 01:43
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