Skip to content

dbt source table schema override is ignored by source() #16366

Description

@greeve

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

A schema configured on an individual source table is retained in the parsed configuration but is ignored when dbt constructs the relation returned by source().

The table-level configuration is present in the parsed manifest as config.schema: sa_das_sadb_ingest_mi, but the source relation uses the parent source schema, sa_das_sadb_ingest.

This prevents one logical source table from being switched between physical schemas without defining a second source or replacing source() with adapter-specific relation construction.

Expected Behavior

The table-level schema configuration should determine the physical relation returned by source() while preserving the existing logical source reference.

Expected relation:

"compile_db"."sa_das_sadb_ingest_mi"."STUDENT_ACADEMIC_UNIT"

The downstream model should continue to use:

{{ source("sadb", "STUDENT_ACADEMIC_UNIT") }}

### Steps To Reproduce

1. Create a dbt project with dbt-core 1.11.7 and define a project variable in `dbt_project.yml`:

   ```yaml
   vars:
     sadb_schema_student_academic_unit: sa_das_sadb_ingest_mi
  1. Define a source in models/ingest/_sadb__soursadb.yml:

    version: 2
    
    sources:
      - name: sadb
        schema: sa_das_sadb_ingest
        tables:
          - name: STUDENT_ACADEMIC_UNIT
            config:
              schema: "{{ var('sadb_schema_student_academic_unit', 'sa_das_sadb_ingest') }}"
  2. Create a model that references the source:

    select *
    from {{ source("sadb", "STUDENT_ACADEMIC_UNIT") }}
  3. Run dbt parse and inspect the source node in target/manifest.json.

  4. Compare the config.schema value with the source node's relation_name and schema values.

Relevant log output

The parsed manifest contains the following source node values:


{
  "relation_name": "\"compile_db\".\"sa_das_sadb_ingest\".\"STUDENT_ACADEMIC_UNIT\"",
  "database": "compile_db",
  "schema": "sa_das_sadb_ingest",
  "identifier": "STUDENT_ACADEMIC_UNIT",
  "config": {
    "schema": "sa_das_sadb_ingest_mi"
  }
}


The relevant source node is:


source.bdp_student_academics_das.sadb.STUDENT_ACADEMIC_UNIT


The manifest demonstrates that dbt retains the table-level configuration but does not use it when constructing
`relation_name`.

Environment

- OS: macOS
- Python: 3.13.5
- dbt-core: 1.11.7
- dbt command used for verification: `dbt parse --no-partial-parse --write-json`

Which database adapter are you using with dbt?

postgres

Additional Context

The current workaround uses adapter.get_relation() with the variable-defined schema:

{{ adapter.get_relation(
    database=target.database,
    schema=var('sadb_schema_student_academic_unit', 'sa_das_sadb_ingest'),
    identifier='STUDENT_ACADEMIC_UNIT'
) }}

This workaround has two disadvantages:

  1. It is adapter-specific and performs a relation lookup that requires a live warehouse connection during compilation.
  2. It does not create the normal dbt source dependency and therefore does not provide equivalent source lineage or source freshness behavior.

The requested behavior is to support schema as a table-level source relation override, or to reject and validate the unsupported configuration instead of silently retaining it in config while ignoring it during relation construction.

Related issue: dbt-core #13705: Support macros or generate_database/schema_name in source configurations.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugengine:v1Concerns the dbt Core v1 engine (Python).status:triageAwaiting initial triage / categorization.triagetype:bugA defect: Fusion behaves incorrectly versus expected/reference behavior.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions