dbt templater fails with `DbtCatalogIntegrationNotFoundError` when using `catalogs.yml`
Search before asking
- I searched the issues and found no similar issues.
What Happened
(disclaimer: used AI for debugging and bug description, but everything has been reviewed and verified by me)
With the dbt templater, sqlfluff lint fails for the whole project if any model sets catalog_name to a catalog defined in catalogs.yml. The failure happens while dbt parses the project, before any file is linted. Excluding the file or using .sqlfluffignore doesn't help.
The dbt CLI (dbt compile, dbt run, dbt build) works fine on the same project.
Root cause: the dbt CLI loads catalogs.yml and registers each catalog with the adapter before parsing:
- It calls
load_catalogs_v2()orload_catalogs(), thenadapter.bridge_v2_catalog()andadapter.add_catalog_integration(). - This happens in
dbt/cli/requires.py::setup_manifestanddbt/parser/manifest.py::parse_manifest.
DbtTemplater does none of this. It calls register_adapter() in dbt_config and then
ManifestLoader.get_full_manifest() in dbt_manifest. The adapter therefore only knows its built-in catalogs
(info_schema and managed_iceberg for BigQuery). While parsing each node, dbt calls
adapter.build_catalog_relation(), which asks the adapter for the custom catalog and fails because it was never
registered.
This affects both the v1 catalogs.yml format and the v2 format (flags.use_catalogs_v2: true), because the
templater skips both loading paths.
Expected Behaviour
sqlfluff lint compiles the project the same way dbt compile does, including catalogs from catalogs.yml, and lints the models normally.
Observed Behaviour
Got error:
=== [dbt templater] Sorting Nodes...
User Error: dbt failed during project compilation. Consider running `dbt debug` or `dbt compile` to get more information from dbt. dbt.adapters.catalogs._exceptions.DbtCatalogIntegrationNotFoundError: Runtime Error
Catalog not found.Received: my_catalogExpected one of: info_schema, managed_iceberg?How to reproduce
Create a dbt project with these files.
dbt_project.yml:name: "example" version: "1.0.0" config-version: 2 profile: "example" flags: use_catalogs_v2: truecatalogs.yml:catalogs: - name: my_catalog type: biglake_metastore table_format: iceberg config: bigquery: external_volume: 'gs://my-bucket' file_format: parquetmodels/my_model.sql:{{ config( materialized = 'table', catalog_name = 'my_catalog', storage_uri = 'gs://my-bucket/my_model', ) }} SELECT 1 AS idAdd a BigQuery profile named
exampleto~/.dbt/profiles.yml.Run
dbt compile. It succeeds.Run
sqlfluff lint models/my_model.sql. It fails with the error above.
Workaround: a sitecustomize.py placed on PYTHONPATH that wraps dbt.adapters.factory.register_adapter and
registers the catalogs itself. With it, linting works:
import contextlib
from dbt.adapters import factory
from dbt.adapters.catalogs import DbtCatalogIntegrationAlreadyExistsError
from dbt.config.catalogs import load_catalogs_v2
from dbt.config.runtime import RuntimeConfig
_original = factory.register_adapter
def _register_adapter_with_catalogs(config, mp_context, adapter_registered_log_level=None):
_original(config, mp_context, adapter_registered_log_level)
if not isinstance(config, RuntimeConfig):
return
adapter = factory.get_adapter(config)
for catalog in load_catalogs_v2(config.project_root, config.project_name, config.cli_vars):
with contextlib.suppress(DbtCatalogIntegrationAlreadyExistsError):
adapter.add_catalog_integration(adapter.bridge_v2_catalog(catalog))
factory.register_adapter = _register_adapter_with_catalogsSuggested fix: in DbtTemplater.dbt_manifest, before calling ManifestLoader.get_full_manifest(), mirror what
setup_manifest does:
- If
use_catalogs_v2is set, load the catalogs withload_catalogs_v2and register each one viabridge_v2_catalogandadd_catalog_integration. - Otherwise, load them with
load_catalogsand register each one's active write integration.
Dialect
bigquery
Version
- sqlfluff 4.3.0
- sqlfluff-templater-dbt 4.3.0
- dbt-core 1.12.4
- dbt-adapters 1.24.5
- dbt-bigquery 1.12.0
- Python 3.13
Configuration
.sqlfluff:
[sqlfluff]
dialect = bigquery
templater = dbt
max_line_length = 120
max_parse_depth = 510
[sqlfluff:templater:dbt]
project_dir = dataThe rest of our config (rule exclusions and layout/capitalisation settings) doesn't affect this; the failure occurs before any rules run.
Are you willing to work on and submit a PR to address the issue?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Source: sqlfluff/sqlfluff