{"record":{"id":"e6aed3cd1ba4c5f6","repo":"dbt-labs/dbt-core","slug":"bigquery-returned-invalid-timepartitioning-field","errorCode":null,"errorMessage":"BigQuery returned invalid 'TimePartitioning.Field'. This is a driver bug.","messagePattern":"BigQuery returned invalid 'TimePartitioning\\.Field'\\. This is a driver bug\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-adapter/src/relation/bigquery/config/components/partition_by.rs","lineNumber":50,"sourceCode":"}\n\nfn from_remote_state(schema: &Schema) -> AdapterResult<PartitionBy> {\n    let metadata = &schema.metadata;\n    let time_partition = if let Some(partition) = metadata.get(\"TimePartitioning.Field\") {\n        let field_name = partition.parse::<String>().unwrap();\n\n        let data_type = schema\n            .fields()\n            .find(&field_name)\n            .map(|(_, field)| {\n                dbt_adapter_sql::types::original_type_string(\n                    dbt_adapter_core::AdapterType::Bigquery,\n                    field,\n                )\n                .expect(\"No 'BIGQUERY:type' in field metadata. This is a driver bug.\")\n                .to_string()\n            })\n            .expect(\"BigQuery returned invalid 'TimePartitioning.Field'. This is a driver bug.\");\n\n        Some(BigqueryPartitionConfig {\n            field: field_name,\n            data_type,\n            __inner__: BigqueryPartitionConfigInner::Time(TimeConfig {\n                granularity: metadata.get(\"TimePartitioning.Type\").unwrap().to_string(),\n                time_ingestion_partitioning: false,\n            }),\n            // TODO(serramatutu): how do we determine the value of this?\n            copy_partitions: false,\n        })\n    } else {\n        None\n    };\n\n    let range_partition = if let Some(partition) = metadata.get(\"RangePartitioning.Field\") {\n        let field = partition.parse::<String>().unwrap();\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/relation/bigquery/config/components/partition_by.rs#L32-L68","documentation":"After resolving the partition field's type, from_remote_state looks up the field named by 'TimePartitioning.Field' in the schema's fields; if no such field exists (or the lookup errors), this second .expect panics, declaring that BigQuery returned a TimePartitioning.Field that doesn't correspond to any field in the returned schema — a driver/API inconsistency treated as a bug.","triggerScenarios":"Calling from_remote_state (via from_remote_state_no_labels / from_remote_state_with_labels) on a schema whose metadata declares 'TimePartitioning.Field' = X, but whose field list contains no field named X (case mismatch, dropped column, or stale metadata).","commonSituations":"Schema fetched from a stale cache while the table was altered; driver returning metadata and fields from different API calls; pseudo/column-case differences (BigQuery is case-insensitive, the Arrow lookup is exact); partitioning on a pseudo-column like _PARTITIONTIME not present in fields.","solutions":["Re-fetch the table schema so metadata and fields come from the same consistent snapshot.","Check for exact-case mismatch between the 'TimePartitioning.Field' value and the field names; normalize case before lookup.","Handle pseudo-columns (e.g. _PARTITIONTIME/_PARTITIONDATE ingestion partitioning) explicitly instead of expecting them in schema.fields().","Report to maintainers if the live BigQuery API genuinely returns a partitioning field absent from the schema."],"exampleFix":"// before\n.expect(\"BigQuery returned invalid 'TimePartitioning.Field'. This is a driver bug.\");\n// after\n.ok_or_else(|| AdapterError::new(AdapterErrorKind::Internal,\n    format!(\"TimePartitioning.Field '{field_name}' not found in schema\")))?","handlingStrategy":"validation","validationCode":"fn partition_field_exists(schema: &arrow_schema::Schema) -> bool {\n    schema.metadata.get(\"TimePartitioning.Field\")\n        .map(|f| schema.fields().find(f).is_some())\n        .unwrap_or(true) // no time partitioning declared\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Re-fetch table schema rather than reusing cached metadata after DDL changes","Normalize field-name case (BigQuery is case-insensitive) before exact lookups","Handle pseudo partitioning columns (_PARTITIONTIME/_PARTITIONDATE) separately from schema fields","Ensure the driver returns metadata and fields from the same API snapshot"],"tags":["bigquery","metadata","driver","schema","panic"],"backgroundTag":"resource-not-found","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}