Repository navigation
fix(loader): avoid false duplicate macro errors after a failed load and name broken macro files - #6305
Conversation
…file token errors Signed-off-by: Connor Hanna <connordouglashanna@gmail.com>
… macro syntax errors Signed-off-by: Connor Hanna <connordouglashanna@gmail.com>
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Description
This PR contains two small fixes to how the loader handles
macros/. Both were issues I found while working on #6297.macros/*.pyfile raised during import, macros from files imported before it stayed in the global registry, so the next project loaded in the same process (a notebook, the LSP, the web UI, a test session) could fail with a falseDuplicate nameerror.SqlMeshLoader._load_scriptsnow restores the registry in afinally.macros/*.sqlname the file: They used to surface as a bare sqlglotTokenError. The loader now raises aConfigErrorwith the file as its location, e.g.Failed to load macro file macros/finance.sql: <error>. Check the file for syntax errors, such as an unterminated string or comment.MacroExtractor.extract()remains unchanged.Follow-up Issues
_load_signalshas the same pattern, so a brokensignals/*.pycan leak signals the same way. I left it out to keep this PR focused, but I'd be happy to follow up separately.Test Plan
The first commit adds two tests to
tests/core/test_loader.pythat fail onmain, and the second commit fixes them.test_failed_macro_load_restores_registry(registry_isolation): after a load fails in the second macro file, the first file's macro is gone, and a second project defining the same macro name with a different body loads.test_untokenizable_macro_file_raises_config_error: theConfigErrornames the file and setslocation, and the registry is unchanged.tests/core/test_loader.pypasses on Python 3.12 and 3.9. All fourmake stylehooks pass. Every stage ofmake fast-testpasses except 6 mssql/fabricpyodbctests, which also fail onmainlocally because unixODBC isn't installed.Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO