Skip to content

fix(dlt): prevent credential type field overwriting db_type in format_config#5857

Draft
mary-mt wants to merge 2 commits into
SQLMesh:mainfrom
mary-mt:fix/dlt-format-config-overwrites-connection-type
Draft

fix(dlt): prevent credential type field overwriting db_type in format_config#5857
mary-mt wants to merge 2 commits into
SQLMesh:mainfrom
mary-mt:fix/dlt-format-config-overwrites-connection-type

Conversation

@mary-mt

@mary-mt mary-mt commented Jun 23, 2026

Copy link
Copy Markdown

Summary

sqlmesh dlt_refresh fails with Error: Unknown connection type 'service_account' when the dlt pipeline uses BigQuery with service-account credentials.

Root cause

format_config initialises config = {"type": db_type} (e.g. "bigquery") then iterates all credential object attributes and writes them into config. BigQuery service-account credentials carry a "type": "service_account" field (from the GCP service account JSON format). This overwrites the "bigquery" key. parse_connection_config then raises:

ConfigError: Unknown connection type 'service_account'

This error fires before model generation starts, even though the direct caller (generate_dlt_models) discards the connection config entirely — it is the _ in:

sqlmesh_models, _, _ = generate_dlt_models_and_settings(...)

The bug only surfaces with BigQuery service-account credentials. OAUTH credentials do not carry a conflicting type field, so anyone who tested dlt_refresh with OAUTH would not have seen it.

Fix

Move config["type"] = db_type to after the credential loop so it cannot be overwritten by credential attributes.

 def format_config(configs: t.Dict[str, str], db_type: str) -> str:
     """Generate a string for the gateway connection config."""
-    config = {
-        "type": db_type,
-    }
-
+    config: t.Dict[str, t.Any] = {}
+
     for key, value in configs.items():
         if key == "password":
             config[key] = f'"{value}"'
         elif key == "username":
             config["user"] = value
         else:
             config[key] = value
 
+    config["type"] = db_type
+
     # Validate the connection config fields

Reproduction

  1. Create a dlt pipeline targeting BigQuery using service-account credentials
  2. Run sqlmesh dlt_refresh <pipeline_name>
  3. Observe: Error: Unknown connection type 'service_account'

Does not affect OAUTH credentials.

…_config

format_config initialises config = {"type": db_type} then iterates all
credential object attributes and writes them into config. BigQuery
service-account credentials carry a "type": "service_account" field
(from the GCP service account JSON format) which overwrites the
"bigquery" key. parse_connection_config then raises:

  ConfigError: Unknown connection type 'service_account'

This error fires before model generation starts, even though the direct
caller (generate_dlt_models) discards the connection config entirely.
The bug only surfaces with BigQuery service-account credentials; OAUTH
credentials do not carry a conflicting type field.

Fix: move config["type"] = db_type to after the credential loop so it
cannot be overwritten by credential attributes.

Signed-off-by: Mary Akowe <mary.akowe@madetech.com>
@mary-mt mary-mt marked this pull request as draft June 23, 2026 13:40
@mday-io

mday-io commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Hi @mary-akowe! :)

May you please review https://github.com/SQLMesh/sqlmesh/blob/main/CONTRIBUTING.md

Some of your tests will fail (e.g., tests/cli/test_cli.py::test_dlt_pipeline)

Signed-off-by: Mary Akowe <mary.akowe@madetech.com>
@mary-mt mary-mt force-pushed the fix/dlt-format-config-overwrites-connection-type branch from 80187bd to b927e56 Compare June 23, 2026 16:04
@mday-io

mday-io commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

It seems that you did not follow the contribution instructions.

I'm seeing failures for make fast-test

@mary-mt

mary-mt commented Jun 24, 2026

Copy link
Copy Markdown
Author

It seems that you did not follow the contribution instructions.

I'm seeing failures for make fast-test

Hello @mday-io, thanks for getting back on this. I initially ran make fast-tests (after following setup instructions), but did not get any failures come up.

  • Main fast tests: 2506 passed, 4 skipped
  • Isolated tests: 3 passed
  • Registry isolation tests: 1 passed
  • Dialect isolated tests: 151 passed

Could you please clarify the errors you are referring?

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.

2 participants