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

fix: reloading relative imports on plugin updates #323

Merged
merged 3 commits into from
Jan 21, 2025

Conversation

jamagalhaes
Copy link
Collaborator

@jamagalhaes jamagalhaes commented Jan 14, 2025

Issue:

KOALA-2422

Description:

This PR solves issues where dependent modules and implicit imports (e.g., __init__.py files) could be executed before being securely evaluated inside a sandbox. It also ensures the latest version of all modules is always loaded during execution.

Key Changes:

  1. Ensured Secure Evaluation of Dependent Modules:

    • Modified the evaluation flow to ensure dependent modules (including __init__.py files) are evaluated securely inside the sandbox before being executed.
    • Prevented premature execution of dependent modules by deferring their evaluation until all implicit imports are properly handled.
    • Introduced recursive evaluation for implicit imports to ensure all modules in the package hierarchy are securely and consistently evaluated.
    • Implemented caching of evaluated modules to prevent redundant or infinite recursive evaluations.
  2. Ensured the Latest Version of Modules is Loaded:

    • Added importlib.reload to reload modules already present in sys.modules.
    • Guarantees that the latest version of any module is always used during execution, addressing issues with outdated module code.

@jamagalhaes jamagalhaes force-pushed the fix/koala-2422-reload-plugin-updates branch from b8e4a9c to cb55577 Compare January 14, 2025 18:00
@jamagalhaes jamagalhaes marked this pull request as ready for review January 14, 2025 19:16
@jamagalhaes jamagalhaes requested a review from a team as a code owner January 14, 2025 19:16
@jamagalhaes jamagalhaes marked this pull request as draft January 15, 2025 17:34
@jamagalhaes jamagalhaes force-pushed the fix/koala-2422-reload-plugin-updates branch from cb55577 to 6bda463 Compare January 16, 2025 15:13
@jamagalhaes jamagalhaes marked this pull request as ready for review January 16, 2025 15:15
Copy link
Member

@beaugunderson beaugunderson left a comment

Choose a reason for hiding this comment

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

looks great, thanks for the comprehensive tests as well!

Copy link
Collaborator

@aduane aduane left a comment

Choose a reason for hiding this comment

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

I just used the same steps I used to confirm the issue and can confirm this fixes it!

Awesome!

@jamagalhaes jamagalhaes force-pushed the fix/koala-2422-reload-plugin-updates branch from 6bda463 to d628b28 Compare January 21, 2025 10:30
@jamagalhaes jamagalhaes merged commit 42f34f8 into main Jan 21, 2025
5 checks passed
@jamagalhaes jamagalhaes deleted the fix/koala-2422-reload-plugin-updates branch January 21, 2025 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants