File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ def wrapper(*args: t.List[t.Any], **kwargs: t.Any) -> t.Any:
1616 return func (* args , ** kwargs )
1717 except Exception as ex :
1818 # these imports are deliberately deferred to avoid the penalty of importing the `sqlmesh`
19- # package for every CLI command
19+ # package up front for every CLI command
2020 from sqlmesh .utils .errors import SQLMeshError
2121 from sqlglot .errors import SqlglotError
2222
@@ -26,13 +26,16 @@ def wrapper(*args: t.List[t.Any], **kwargs: t.Any) -> t.Any:
2626 else :
2727 raise
2828 finally :
29- from sqlmesh import Context
30-
3129 context_or_obj = args [0 ]
3230 sqlmesh_context = (
3331 context_or_obj .obj if isinstance (context_or_obj , click .Context ) else context_or_obj
3432 )
35- if isinstance (sqlmesh_context , Context ):
36- sqlmesh_context .close ()
33+ if sqlmesh_context is not None :
34+ # important to import this only if a context was created
35+ # otherwise something like `sqlmesh_dbt run --help` will trigger this import because it's in the finally: block
36+ from sqlmesh import Context
37+
38+ if isinstance (sqlmesh_context , Context ):
39+ sqlmesh_context .close ()
3740
3841 return wrapper
You can’t perform that action at this time.
0 commit comments