Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apparently wrong type of CopyOptions.metadata #2389

Closed
anantakrishna opened this issue Jan 10, 2024 · 4 comments · Fixed by #2439
Closed

Apparently wrong type of CopyOptions.metadata #2389

anantakrishna opened this issue Jan 10, 2024 · 4 comments · Fixed by #2439
Assignees
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@anantakrishna
Copy link

anantakrishna commented Jan 10, 2024

It seems that the type of CopyOptions.metadata is wrong.

Prior to #2234 (landed in f48dcd2), CopyOptions.metadata was of type Metadata=any: https://github.com/googleapis/nodejs-storage/pull/2234/files#diff-bc9705d0f7a567399044dfc66ccc82d4d9aa1cff116842a0094d54e463c9ecbcL313, https://github.com/googleapis/nodejs-storage/pull/2234/files#diff-dd08f09f3839e8051415914bfa81750cc0f28ae2d9b1d6b95eb87bb0efff2577L48. This fact indicates that this property refers to the custom metadata. Moreover, cacheControl, contentType and other known metadata properties are declared directly on the CopyOptions interface.

After that PR was merged, CopyOptions.metadata got type FileMetadata, which itself contains cacheControl, contentType, as well as nested metadata, which is essentially a Record<string, string> and means “custom metadata”.

It seems to me that CopyOptions.metadata should be of type Record<string, string> directly. This is confirmed by the code below.

Steps to reproduce

file.copy(to,
  {
    contentType: 'outer', // A property from CopyOptions
    metadata: { // Typed as FileMetadata
      contentType: 'internal',
      custom1: 'outer', // Not a part of FileMetadata, but allowed by TypeScript
      metadata: { // Intended to hold custom metadata, but ignored
        custom2: 'internal'
      }
    },
  }
);

The copied file gets the following metadata:

  • Content-Type: outer
  • Custom metadata:
    • contentType: inner - note how a property of FileMetadata.contentType it became a custom metadata.
    • custom1: outer

Whereas custom2 is ignored.

image


Environment details

  • OS: any
  • Node.js version: any
  • npm version: any
  • @google-cloud/storage version: 7.7.0
@anantakrishna anantakrishna added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 10, 2024
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Jan 10, 2024
@ddelgrosso1
Copy link
Contributor

Thanks @anantakrishna we will take a look and see about getting it fixed up.

@ddelgrosso1 ddelgrosso1 self-assigned this Jan 10, 2024
@anantakrishna
Copy link
Author

Thanks. Just in case, here are related changes: #1406, #1426.

@vishwarajanand
Copy link
Contributor

There are a couple of issues here:

  1. I am not sure whether CopyOptions.metadata tyope should be reverted, I raised a PR but will await @ddelgrosso1 to reassert. I do think it should be changed though for neatness.

  2. For the repro provided, I can validate that the nested metadata is indeed sent on request stream, but the backend seems to be ignoring (because it's nested?). There are a few approaches for end users here, but the library should not be doing either of these:

    • Json encode the nested metadata into first level of custom metadata.
    • Flatten all nested metadata down to first level

@ddelgrosso1
Copy link
Contributor

  1. We discussed offline but putting here for visibility as well. Yes, CopyOptions.metadata should be reverted. It should not be of type FileMetadata. CopyOptions was meant to represent editable metadata and I missed this during my previous changes.

  2. This point should become moot if we change it back to the correct typing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants