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

topic(setMetadata): messageRetentionDuration not working #1587

Closed
ndeitch opened this issue Jun 14, 2022 · 2 comments · Fixed by #1778
Closed

topic(setMetadata): messageRetentionDuration not working #1587

ndeitch opened this issue Jun 14, 2022 · 2 comments · Fixed by #1778
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub 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

@ndeitch
Copy link

ndeitch commented Jun 14, 2022

Environment details

  • OS: MacOS Monterey v12.4
  • Node.js version: v16.14.2
  • npm version: 8.5.0
  • @google-cloud/pubsub version: 3.0.1

Steps to reproduce

Create subscription & setMetadata
const THREE_DAYS_IN_SECONDS = 3 * 24 * 60 * 60
const [topic] = await new PubSub().topic('test').get({ autoCreate: true })
await topic.setMetadata({ messageRetentionDuration: { seconds: THREE_DAYS_IN_SECONDS  } })
Error thrown
Error: 3 INVALID_ARGUMENT: Invalid update_mask provided in the UpdateTopicRequest: 'messageRetentionDuration' is not a known Topic field. Note that field paths must be of the form 'push_config' rather than 'pushConfig'.

It seems that messageRetentionDuration is not mapped correctly given this test:

messageRetentionDuration: threeDaysInSeconds,

@ndeitch ndeitch 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 Jun 14, 2022
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/nodejs-pubsub API. label Jun 14, 2022
@nguyen-vo
Copy link

@ndeitch here is my temporary workaround
the topic.request is implemented based on the topic.setMetadata() function. So now you the parameter of setMetadata go to reqOpts.topic, fields are camelCase and in the reqOpts.updateMask.paths. specify field you want to update with _

 const topic = client.topic(topicName);
    const [topicExists] = await topic.exists();
    if (topicExists) {
      console.log(`Topic ${topicName} already exists`);
      return;
    }
    try {
      await topic.create();
      topic.request(
        {
          client: 'PublisherClient',
          method: 'updateTopic',
          reqOpts: {
            topic: {
              name: PubSubClient.getFormattedTopic(topicName, client.projectId),
              messageRetentionDuration: { seconds: '604800s' },
            },
            updateMask: {
              paths: ['message_retention_duration'],
            },
          },
          gaxOpts: {},
        },
        (err, data) => {
          if (err) {
            console.error(`Error setting topic metadata ${topicName}`, err);
          }
        },
      );
      console.log(`Topic ${topicName} created`);
    } catch (err) {
      console.error(`Error creating topic ${topicName}`, err);
    }

@feywind
Copy link
Collaborator

feywind commented Aug 2, 2022

Thanks @nguyen-vo for the workaround. I peeked at the code, and it looks like this method (in src/topic.ts) was probably written before we had multi-word topic metadata to update. So it needs to convert the name for the update mask. This shouldn't be a lot of effort, but there's a bunch of work ahead of it in the queue right now. :|

@brijk7 brijk7 added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Mar 8, 2023
@kamalaboulhosn kamalaboulhosn added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed priority: p3 Desirable enhancement or fix. May not be included in next release. labels Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub 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.

5 participants