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

Refactor lazy imports to avoid accidental eager imports #13296

Merged
merged 22 commits into from
May 30, 2024

Conversation

abrookins
Copy link
Collaborator

@abrookins abrookins commented May 9, 2024

This work is part of our effort to speed up CLI commands. The lazy_import function inadvertently imported more things when you called it, particularly a bunch of Docker and Kubernetes packages. The problem was the function's call to inspect.stack(), which was only necessary to produce a detailed error message. I tightened the error message to remove the need to call inspect.stack().

Example

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • This pull request includes a label categorizing the change e.g. maintenance, fix, feature, enhancement, docs.

For documentation changes:

  • This pull request includes redirect settings in netlify.toml for files that are removed or renamed.

For new functions or classes in the Python SDK:

  • This pull request includes helpful docstrings.
  • If a new Python file was added, this pull request contains a stub page in the Python SDK docs and an entry in mkdocs.yml navigation.

Copy link

netlify bot commented May 9, 2024

Deploy Preview for prefect-docs-preview ready!

Name Link
🔨 Latest commit 78e8a79
🔍 Latest deploy log https://app.netlify.com/sites/prefect-docs-preview/deploys/664368afbb6fde0008318711
😎 Deploy Preview https://deploy-preview-13296--prefect-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@abrookins abrookins changed the title WIP on refactoring lazy imports Refactor lazy imports to fix a bug May 13, 2024
@abrookins abrookins added the fix A fix for a bug in an existing feature label May 13, 2024
@abrookins
Copy link
Collaborator Author

Tests are currently failing due to an upstream change in the apprise library that we're working to fix.

@abrookins abrookins marked this pull request as ready for review May 13, 2024 14:35
@abrookins abrookins requested a review from a team as a code owner May 13, 2024 14:35
Copy link
Collaborator

@chrisguidry chrisguidry left a comment

Choose a reason for hiding this comment

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

Super interesting, what mechanism caused the additional imports to happen?

@abrookins
Copy link
Collaborator Author

@chrisguidry I haven't had time to dig into this yet, but it was inspect.stack()[1].

@abrookins
Copy link
Collaborator Author

abrookins commented May 25, 2024

The problem was that using inspect would evaluate imports at the frame above the current frame, which would end up eagerly importing kubernetes.

@abrookins abrookins changed the title Refactor lazy imports to fix a bug Refactor lazy imports to avoid accidental eager imports May 30, 2024
@abrookins abrookins merged commit 20cdf81 into main May 30, 2024
24 of 26 checks passed
@abrookins abrookins deleted the remove-more-imports branch May 30, 2024 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix A fix for a bug in an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants