diff --git a/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/checkUpdates.ts b/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/checkUpdates.ts index 6313f32cc..e18af3d14 100644 --- a/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/checkUpdates.ts +++ b/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/checkUpdates.ts @@ -23,7 +23,7 @@ export async function tableRequiresUpdate({ const { metadata } = table; /** Check clustering */ - const configCluster = JSON.stringify(config.clustering); + const configCluster = JSON.stringify(config.clustering || []); const tableCluster = JSON.stringify(metadata.clustering?.fields || []); if (configCluster !== tableCluster) return true; diff --git a/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/handleFailedTransactions.ts b/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/handleFailedTransactions.ts index 4addaeec9..5bf894430 100644 --- a/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/handleFailedTransactions.ts +++ b/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/handleFailedTransactions.ts @@ -7,15 +7,30 @@ if (!admin.apps.length) { initializeApp(); } +const settingsApplied = new Set(); + +const getConfiguredFirestore = (instanceId?: string) => { + const db = instanceId ? getFirestore(instanceId) : getFirestore(); + if (!settingsApplied.has(instanceId)) { + settingsApplied.add(instanceId); + try { + db.settings({ ignoreUndefinedProperties: true }); + } catch { + // Firestore.settings() throws if the singleton has already been used + // elsewhere in the process. The dead-letter path doesn't strictly + // depend on ignoreUndefinedProperties, so swallow rather than crash + // and mask the original BigQuery error that led us here. + } + } + return db; +}; + export default async ( rows: any[], config: ChangeTrackerConfig, e: Error ): Promise => { - const db = getFirestore(config.firestoreInstanceId!); - db.settings({ - ignoreUndefinedProperties: true, - }); + const db = getConfiguredFirestore(config.firestoreInstanceId); const batchArray = [db.batch()]; let operationCounter = 0; diff --git a/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/index.ts b/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/index.ts index 7b6f8a15e..f6202970e 100644 --- a/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/index.ts +++ b/firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/index.ts @@ -341,14 +341,14 @@ export class FirestoreBigQueryEventHistoryTracker await clustering.updateClustering(metadata); - const documentIdColExists = fields.find( + const documentIdColExists = fields.some( (column) => column.name === "document_id" ); - const pathParamsColExists = fields.find( + const pathParamsColExists = fields.some( (column) => column.name === "path_params" ); - const oldDataColExists = fields.find( + const oldDataColExists = fields.some( (column) => column.name === "old_data" );