Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

UploadOptions mutates provided object #1891

@sethvargo

Description

@sethvargo
  1. Is this a client library issue or a product issue?

    This is a client-library issue.

  2. Did someone already solve this?

    I could not find anything.

  3. Do you have a support contract?

    I work for Google 😄 .

Environment details

  • OS: Mac 12.3.1 (21E258)
  • Node.js version: 16.14.0
  • npm version: 8.3.1
  • @google-cloud/storage version: 5.19.3

Steps to reproduce

import { Storage } from '@google-cloud/storage';

async function main() {
  const opts = {
    metadata: {},
  };

  console.log('before: ', { opts });

  const storage = new Storage({
    projectId: 'sv-actions-test',
  });
  await storage.bucket('sv-actions-test').upload('package.json', opts);

  console.log('after: ', { opts });
}

main();

The opts passed to upload are modified:

before: { opts: { metadata: {} } }
after: { opts: { metadata: { contentType: 'application/json' } } }

It's very unexpected and undocumented that the object passed to upload would mutate the properties of that object. This was the root cause of an extremely difficult to debug bug in the upload-cloud-storage GitHub Action, causing the wrong Content-Type to be applied to object uploads.

The workaround is to deep copy the entire object before passing it to upload. I would expect the SDK to handle this and not mutate objects it is given. Other functions in the SDK may have this same problem.

I believe the issue is here.

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/nodejs-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions