Skip to content

Error when creating external models #919

@hughcameron

Description

@hughcameron

I'm encountering an error when trying to create external models.

Based on my reading of the documentation, sqlmesh create_external_models accepts no arguments and should be run from the root of the project.

The expected behaviour is for the CLI to create an external model represented as a YAML file as described here.

Please see below the stack trace.

sqlmesh create_external_models
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/bin/sqlmesh", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/click/decorators.py", line 38, in new_func
    return f(get_current_context().obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/sqlmesh/cli/__init__.py", line 20, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/sqlmesh/cli/main.py", line 392, in create_external_models
    obj.create_external_models()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/sqlmesh/core/context.py", line 847, in create_external_models
    models = self._models or self._loader.load(self, update_schemas=False).models
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/sqlmesh/core/loader.py", line 132, in load
    macros, hooks, jinja_macros = self._load_scripts()
                                  ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/sqlmesh/core/loader.py", line 226, in _load_scripts
    if self._import_python_file(path, context_path):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/site-packages/sqlmesh/core/loader.py", line 366, in _import_python_file
    return importlib.import_module(module_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/dag/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'macros'

Also, here's a list of versions I'm running:

❯ pip list | grep sql
sqlglot                       14.1.1
sqlmesh                       0.12.2
sqlparse                      0.4.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions