Skip to content

Conversation

@dmadisetti
Copy link
Collaborator

@dmadisetti dmadisetti commented Aug 1, 2025

📝 Summary

Follow up to #5758

Solves reference dependency issues in an external lib, by creating a partial graph of toplevel functions on invocation. Previously, the "graph" of an external function was allowed to be blank. This is incorrect, since both setup cell values, and other top level definitions can be exposed to the cached function.

For example in tests/_save/external_decorators/transitive_wrappers_1.py

with app.setup:
    ...
    impure_state = ...

@app.function
def my_impure_decorator(func):
    """An impure decorator that depends on impure_state"""

    @functools.wraps(func)
    def wrapper(*args: Any, **kwargs: Any):
        # Decorator depends on impure_state
        wrapper._value = ... # dependent on impure state ...
        return func(*args, **kwargs)

    return wrapper

...

@app.function
@my_impure_decorator
def pure_function():
    # This function itself is pure (no external dependencies)
    return 42

...

on from external_decorators.transitive_wrappers_1 import pure_function a partial graph is constructed to invalidate pure_function based on its relationship pure_function -> impure_function -> impure_state. Whereas before, we just ignored these relationships because pure_function was determined to be an external function and thus 'pure'.

@vercel
Copy link

vercel bot commented Aug 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marimo-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 4, 2025 11:24pm

@dmadisetti dmadisetti added the bug Something isn't working label Aug 1, 2025
@dmadisetti dmadisetti changed the base branch from main to dm/wrapper-unrevert-base August 1, 2025 17:25
@dmadisetti dmadisetti changed the title fix: External decorators in the case of wrapped functions now work fix: cache wrapper fixes and added tests (followup) Aug 1, 2025
LOGGER = _loggers.marimo_logger()


def graph_from_app(fn: Callable[..., Any], app: App) -> DirectedGraph:
Copy link
Collaborator Author

@dmadisetti dmadisetti Aug 1, 2025

Choose a reason for hiding this comment

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

I wouldn't mind a bit of a sanity check here.

This is the setup:

  • we are loading a marimo notebook as a module
  • a toplevel cache decorated function has dependencies on other top level dependencies.

This function is called on first invocation, where we do a best effort to create the graph thus far with top level definitions.

Notably, function definitions can be out of order (solved by waiting for invocation), but also invoked even before the app is done being constructed (via decorators). We grab app from the scope of the function declaration, and construct our own version of the graph with only top level deps.

@dmadisetti
Copy link
Collaborator Author

Woops. Saw the fastforward requested everyone. Sorry about that. rebasing

@dmadisetti dmadisetti force-pushed the dm/wrapper-unrevert branch from a6c247e to 3d617b2 Compare August 4, 2025 20:25
@dmadisetti dmadisetti removed the request for review from Light2Dark August 4, 2025 20:25
@dmadisetti dmadisetti removed the request for review from manzt August 4, 2025 20:25
dmadisetti added a commit that referenced this pull request Aug 4, 2025
 (#5876)

## 📝 Summary

Restores #5758 with additional
tests. Broken into 2 PRs to make the diffs more evident.

 - The first PR is bulk revert
- the follow up PR (#5873) addresses reference dependency issues in an
external lib.
Base automatically changed from dm/wrapper-unrevert-base to main August 4, 2025 23:12
@dmadisetti dmadisetti removed the documentation Improvements or additions to documentation label Aug 4, 2025
@dmadisetti dmadisetti changed the title fix: cache wrapper fixes and added tests (followup) fix: improved robustness of cache wrapper in module contexts Aug 5, 2025
@mscolnick mscolnick added the bash-focus Area to focus on during release bug bash label Aug 5, 2025
@dmadisetti dmadisetti merged commit 15e2ea9 into main Aug 6, 2025
37 of 38 checks passed
@dmadisetti dmadisetti deleted the dm/wrapper-unrevert branch August 6, 2025 20:40
@github-actions
Copy link

github-actions bot commented Aug 6, 2025

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.14.17-dev38

dmadisetti added a commit that referenced this pull request Aug 7, 2025
## 📝 Summary

Adds tests to ensure caching works on app embed. Cherrypicked out of
#5873 because the solution for checking for a long ID seemed a bit
hacky, and I figured the tests were worth isolating. Closes #5312
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants