@@ -49,8 +49,13 @@ export class Builder {
4949
5050 const tableMetadataByTarget = new Map < string , dataform . ITableMetadata > ( ) ;
5151
52+ // Normalize warehouse state targets to match compiled targets for consistent lookups.
53+ // This is necessary because targets from the warehouse may have a database field set
54+ // (from BigQuery credentials) while compiled targets may not have a database field
55+ // if defaultDatabase is not specified in workflow_settings.yaml.
5256 this . warehouseState . tables . forEach ( tableState => {
53- tableMetadataByTarget . set ( targetStringifier . stringify ( tableState . target ) , tableState ) ;
57+ const normalizedTarget = this . normalizeWarehouseTarget ( tableState . target ) ;
58+ tableMetadataByTarget . set ( targetStringifier . stringify ( normalizedTarget ) , tableState ) ;
5459 } ) ;
5560
5661 const actions : dataform . IExecutionAction [ ] = [ ] . concat (
@@ -121,4 +126,22 @@ export class Builder {
121126 actionDescriptor : action . actionDescriptor
122127 } ) ;
123128 }
129+
130+ private normalizeWarehouseTarget ( warehouseTarget : dataform . ITarget ) : dataform . ITarget {
131+ // If the warehouse target has a database field and the compiled graph doesn't have a
132+ // defaultDatabase, we should remove the database field from the warehouse target
133+ // to match the format of the compiled targets. This ensures consistent lookups
134+ // when defaultDatabase is not specified in workflow_settings.yaml.
135+ if (
136+ warehouseTarget . database &&
137+ ! this . prunedGraph . projectConfig . defaultDatabase
138+ ) {
139+ return dataform . Target . create ( {
140+ schema : warehouseTarget . schema ,
141+ name : warehouseTarget . name
142+ } ) ;
143+ }
144+ // Otherwise return the warehouse target as-is
145+ return warehouseTarget ;
146+ }
124147}
0 commit comments