Skip to content

Comments

Updating Macro to be lazy loaded#5708

Open
Tom-Fynes wants to merge 4 commits intoTobikoData:mainfrom
Tom-Fynes:#5692
Open

Updating Macro to be lazy loaded#5708
Tom-Fynes wants to merge 4 commits intoTobikoData:mainfrom
Tom-Fynes:#5692

Conversation

@Tom-Fynes
Copy link

@Tom-Fynes Tom-Fynes commented Feb 20, 2026

Fixes #5692

This pull request refactors the macro evaluation logic in sqlmesh/core/macros.py to introduce lazy loading for Python environments, improve error handling for missing macro dependencies, and enhance code readability. The changes enable projects to share state databases without requiring all external dependencies to be present, and provide clearer error messages when macros fail to load. Additionally, the code has been reformatted for better readability, and error messages have been made more consistent throughout the file.

Macro Environment Loading and Error Handling:

  • Introduced lazy loading for Python environment executables, deferring imports and macro definitions until they are actually needed. This allows projects to share state databases without requiring all dependencies to be present at load time. Added _unloaded_executables and _failed_imports tracking, and refactored macro loading logic into a new _load_python_env method. (sqlmesh/core/macros.py) [1] [2]
  • Enhanced error handling in macro invocation: if a macro fails to load due to a missing dependency, a clear error message is raised, explaining the likely cause and how to proceed. (sqlmesh/core/macros.py)

Code Readability and Consistency:

Error Message Improvements:

  • Standardized error messages for missing variables, schema issues, and invalid arguments, making them more descriptive and user-friendly. (sqlmesh/core/macros.py) [1] [2] [3] [4] [5] [6] [7] [8]

General Cleanup:

  • Removed unused import prepare_env from the file. (sqlmesh/core/macros.py)

These changes make the macro evaluation system more robust, maintainable, and easier for users to debug when issues arise.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Fynes seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

ModuleNotFoundError when multiple projects share state database with external macro dependencies

2 participants