Skip to content

Update dbt integration doc sqlmesh init command to avoid init error#4066

Merged
themisvaltinos merged 1 commit intoSQLMesh:mainfrom
JunqiYangjqy:doc/update_dbt_integration_doc
Apr 1, 2025
Merged

Update dbt integration doc sqlmesh init command to avoid init error#4066
themisvaltinos merged 1 commit intoSQLMesh:mainfrom
JunqiYangjqy:doc/update_dbt_integration_doc

Conversation

@JunqiYangjqy
Copy link
Contributor

Description

sqlmesh version: 0.170.1
engine: snowflake

When following the documentation here and running the command sqlmesh init -t dbt, keeps getting error like below:

Traceback (most recent call last):
  File "/home/venvs/sqlmesh_env/bin/sqlmesh", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/sqlmesh/cli/__init__.py", line 29, in wrapper
    return handler(sqlmesh_context, lambda: func(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/sqlmesh/cli/__init__.py", line 38, in _default_exception_handler
    return func()
           ^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/sqlmesh/cli/__init__.py", line 29, in <lambda>
    return handler(sqlmesh_context, lambda: func(*args, **kwargs))
                                            ^^^^^^^^^^^^^^^^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/sqlmesh/core/analytics/__init__.py", line 82, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/sqlmesh/cli/main.py", line 159, in init
    init_example_project(
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/sqlmesh/cli/example_project.py", line 287, in init_example_project
    _create_config(config_path, dialect, settings, start, template)
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/sqlmesh/cli/example_project.py", line 323, in _create_config
    project_config = _gen_config(dialect, settings, start, template)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/venvs/sqlmesh_env/lib/python3.11/site-packages/sqlmesh/cli/example_project.py", line 72, in _gen_config
    f"      # {doc_link.format(engine_link=engine_link)}\n{connection_settings}"
                                                           ^^^^^^^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'connection_settings' where it is not associated with a value
(sqlmesh_env) FAIL: 1

After looking at the example_project.py, looks like it needs an engine name to be passed to a variable dialect - i.e. sqlmesh init -t dbt athena/snowflake/mysql - As long as the engine is in CONNECTION_CONFIG_TO_TYPE.

Therefore, by updating the documentation with the engine type, this command works as expected.

(sqlmesh_env) user@host: /home/sqlmesh_snowflake
➜   sqlmesh init -t dbt snowflake
**************The dialect is: snowflake
**************The CONNECTION_CONFIG_TO_TYPE is:
{
    'athena': <class 'sqlmesh.core.config.connection.AthenaConnectionConfig'>,
    'azuresql': <class 'sqlmesh.core.config.connection.AzureSQLConnectionConfig'>,
    'bigquery': <class 'sqlmesh.core.config.connection.BigQueryConnectionConfig'>,
    'clickhouse': <class 'sqlmesh.core.config.connection.ClickhouseConnectionConfig'>,
    'databricks': <class 'sqlmesh.core.config.connection.DatabricksConnectionConfig'>,
    'duckdb': <class 'sqlmesh.core.config.connection.DuckDBConnectionConfig'>,
    'gcp_postgres': <class 'sqlmesh.core.config.connection.GCPPostgresConnectionConfig'>,
    'mssql': <class 'sqlmesh.core.config.connection.MSSQLConnectionConfig'>,
    'motherduck': <class 'sqlmesh.core.config.connection.MotherDuckConnectionConfig'>,
    'mysql': <class 'sqlmesh.core.config.connection.MySQLConnectionConfig'>,
    'postgres': <class 'sqlmesh.core.config.connection.PostgresConnectionConfig'>,
    'redshift': <class 'sqlmesh.core.config.connection.RedshiftConnectionConfig'>,
    'risingwave': <class 'sqlmesh.core.config.connection.RisingwaveConnectionConfig'>,
    'snowflake': <class 'sqlmesh.core.config.connection.SnowflakeConnectionConfig'>,
    'spark': <class 'sqlmesh.core.config.connection.SparkConnectionConfig'>,
    'trino': <class 'sqlmesh.core.config.connection.TrinoConnectionConfig'>
}

@CLAassistant
Copy link

CLAassistant commented Apr 1, 2025

CLA assistant check
All committers have signed the CLA.

@JunqiYangjqy JunqiYangjqy changed the title Update dbt integration doc init command to avoid project init error Update dbt integration doc sqlmesh init command to avoid init error Apr 1, 2025
@tobymao
Copy link
Contributor

tobymao commented Apr 1, 2025

@themisvaltinos is there an issue here with the init?

@themisvaltinos
Copy link
Contributor

@themisvaltinos is there an issue here with the init?

No, the need to specify the dialect is simply mentioned in the init cli usage docs, but not in the dbt docs. Thanks for your contribution @JunqiYangjqy only if you could please rename engine-name to dialect to keep it consistent with the rest of the documentation.

@JunqiYangjqy
Copy link
Contributor Author

@themisvaltinos is there an issue here with the init?

No, the need to specify the dialect is simply mentioned in the init cli usage docs, but not in the dbt docs. Thanks for your contribution @JunqiYangjqy only if you could please rename engine-name to dialect to keep it consistent with the rest of the documentation.

Thanks all :)
Will update the name tomorrow morning.
Cheers

@JunqiYangjqy JunqiYangjqy force-pushed the doc/update_dbt_integration_doc branch from b7cbb6a to b8f4662 Compare April 1, 2025 20:36
@JunqiYangjqy
Copy link
Contributor Author

@themisvaltinos Updated :) Thanks

@themisvaltinos
Copy link
Contributor

@themisvaltinos Updated :) Thanks

thank you! feel free to merge

@themisvaltinos themisvaltinos merged commit 326dc98 into SQLMesh:main Apr 1, 2025
19 checks passed
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.

4 participants