-
Notifications
You must be signed in to change notification settings - Fork 98
Description
Describe the bug
Filing on behalf of a customer (Slack thread).
When using job-label: true in the query-comment config for BigQuery, dbtf compile panics at runtime. The panic occurs because the resolved query comment JSON may contain non-string values (e.g., nested objects like relation), and the code at query_comment.rs:128 calls value.as_str().expect("Expected job label to be a string") which panics on non-string JSON values.
There are two related issues:
- Panic on valid config:
job-label: trueis a valid boolean value, but causes a panic when the resolved query comment contains non-string JSON values (objects, arrays, numbers, booleans). - Misleading validation feedback: Setting
job-label: "some_string"correctly rejects withdbt1005: Invalid query comment: job-label must be a bool— but since the valid bool valuetruepanics, this creates a confusing experience where neither bool nor string works.
What version of dbt Fusion is this bug in? (find out by running dbt --version)
dbt-fusion 2.0.0-preview.114
Is this a discrepancy between the dbt Fusion Engine and dbt Core? Check one.
- YES
- NO
To Reproduce
dbt_project.yml:
query-comment:
comment: |
{% if target.name == 'dev' %}
{{ query_comment(node, 'dev') }}
{% else %}
{{ query_comment(node, env_var('DBT_EXECUTED_BY', 'other')) }}
{% endif %}
job-label: trueRun:
dbtf compileOutput:
dbt-fusion 2.0.0-preview.114
Loading profiles.yml
Fetching packages.yml
Rendering [━━━━━━━━━━━━━━━━━━━━] 22697/22698 22697 succeeded | 1 in-progress
unit_test:base_contract_renewal_dates [0.5s]
panic: panicked at fs/sa/crates/dbt-adapter/src/query_comment.rs:128:55:
Expected job label to be a string
Root Cause
In query_comment.rs:128, the get_job_labels_from_query_comment method iterates over the parsed JSON map and calls:
sanitize_label(value.as_str().expect("Expected job label to be a string"))This assumes every value in the query comment JSON is a string, but query comments commonly contain nested objects (e.g., relation: {"database": "...", "schema": "...", "identifier": "..."}), numbers, or booleans. The .expect() call causes a panic instead of handling these gracefully.
The validation in resolve_query_comment.rs:41-47 correctly validates that job-label itself is a bool, but nothing validates or handles non-string values within the resolved query comment JSON when converting to BigQuery job labels.
Expected behavior
Non-string JSON values in the resolved query comment should be handled gracefully when job-label: true — either by converting them to strings (e.g., via to_string() / serde_json::to_string()) or by skipping/flattening nested values. This is how dbt Core + dbt-bigquery handles it via connections.py#L629.
Operating System and CPU Type (please complete the following information):
- Mac/Windows/Linux? macOS
- X86 or ARM? ARM