From f7f1bba0948fddf2e7e79eca038c6f28d01f5d9f Mon Sep 17 00:00:00 2001 From: Sakthivel Subramanian Date: Mon, 30 Nov 2026 18:39:18 +0000 Subject: [PATCH] fix(spanner): revert sharing caller-provided GoogleAuth from #9957 Partially reverts #9957 (`3ce79be100`, `fix(spanner): respect universeDomain and custom endpoints in metrics`). Restores `this.auth = new GoogleAuth(this.options)` so a caller-provided `options.auth` instance is not shared with `Spanner.auth` or built-in metrics. --- handwritten/spanner/src/index.ts | 5 +---- handwritten/spanner/test/index.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/handwritten/spanner/src/index.ts b/handwritten/spanner/src/index.ts index 5b63004d19d..7235b1f8d73 100644 --- a/handwritten/spanner/src/index.ts +++ b/handwritten/spanner/src/index.ts @@ -524,10 +524,7 @@ class Spanner extends GrpcService { this._isInSecureCredentials = options.sslCreds?._isSecure() === false; this.options = options; - this.auth = - options.auth instanceof GoogleAuth - ? options.auth - : new GoogleAuth(this.options); + this.auth = new GoogleAuth(this.options); this.clients_ = new Map(); this.instances_ = new Map(); this.instanceConfigs_ = new Map(); diff --git a/handwritten/spanner/test/index.ts b/handwritten/spanner/test/index.ts index 974fcd6cf82..491735c55a1 100644 --- a/handwritten/spanner/test/index.ts +++ b/handwritten/spanner/test/index.ts @@ -678,11 +678,15 @@ describe('Spanner', () => { } }); - it('should reuse a caller-provided GoogleAuth instance', () => { + it('should not share a caller-provided GoogleAuth instance with Spanner.auth or metrics exporter', () => { const callerAuth = Object.create(fakeGoogleAuth.prototype); callerAuth.getProjectId = cb => cb && cb(null, 'caller-project'); - const clientWithCallerAuth = new Spanner(asAny({auth: callerAuth})); - assert.strictEqual(clientWithCallerAuth.auth, callerAuth); + const clientWithCallerAuth = new Spanner( + asAny({projectId: 'caller-project', auth: callerAuth}), + ); + assert.notStrictEqual(clientWithCallerAuth.auth, callerAuth); + assert.strictEqual(recordedExporterCalls.length, 1); + assert.notStrictEqual(recordedExporterCalls[0].options.auth, callerAuth); assert.notStrictEqual(new Spanner().auth, callerAuth); });