This repository was archived by the owner on Mar 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 394
This repository was archived by the owner on Mar 3, 2026. It is now read-only.
UploadOptions mutates provided object #1891
Copy link
Copy link
Closed
Labels
api: storageIssues related to the googleapis/nodejs-storage API.Issues related to the googleapis/nodejs-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-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.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
-
Is this a client library issue or a product issue?
This is a client-library issue.
-
Did someone already solve this?
I could not find anything.
-
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/storageversion: 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: storageIssues related to the googleapis/nodejs-storage API.Issues related to the googleapis/nodejs-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-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.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.