nodejs-docs-samples icon indicating copy to clipboard operation
nodejs-docs-samples copied to clipboard

Google Cloud Retail: updateMask values must be snake_case despite being camelCase on the Product Interface

Open sofisl opened this issue 3 years ago • 1 comments

See: https://github.com/googleapis/google-cloud-node/issues/4195

sofisl avatar Apr 27 '23 19:04 sofisl

I think this is still an issue. However it executes okay with the API but the SDK throws an error.

async function updateMinInstances(
  functionName: string,
  functionRegion: string,
  minInstances: number
): Promise<void> {
  const name = `projects/${PROJECT_ID}/locations/${functionRegion}/functions/${functionName}`;
  try {
    const request: protos.google.cloud.functions.v1.IUpdateFunctionRequest = {
      function: {
        name,
        minInstances,
        maxInstances: null // Setting maxInstances to null (or omitting it) effectively removes the limit.
      },
      // Corrected the updateMask to be an object with a 'paths' array.
      updateMask: {
        paths: ['min_instances', 'max_instances']
      }
    };

    // Make the API call to update the function
    const [operation] = await client.updateFunction(request);
    const [response] = await operation.promise();
    console.log(
      `Successfully updated minInstances to ${minInstances} for function: ${functionName}`,
      response
    );
  } catch (error) {
    // We cast the error to be able to access its message property.
    console.error(`Error updating function ${functionName}: ${(error as Error).message}`, error);
  }
}

tmk1991 avatar Aug 10 '25 21:08 tmk1991