Skip to content

gapic-generator: --resource-name-alias is ignored for file-level resource definitions, causing false-positive namespace collisions #16952

@ohmayr

Description

@ohmayr

When generating a client library that imports an external dependency with a file-level resource definition (e.g., google.api.resource_definition), the generator falsely throws a namespace collision error even if an explicit --resource-name-alias is provided via the CLI/Bazel arguments. The generator's AST builder fails to pass the alias dictionary to the dummy MessageType constructed for file-level resources.

Steps to Reproduce

  • Set the following option in BUILD.bazel file for dialogflow:
opt_args = [
    "resource-name-alias=ces.googleapis.com/Tool:CesTool", 
    ],
  • Regenerate v2 or v2beta1 for dialogflow using librarian.

Output:

ValueError: 
Fatal: Namespace collision detected for resource type 'Tool'.
Resources 'ces.googleapis.com/Tool' and 'dialogflow.googleapis.com/Tool' both flatten to the exact same method name.
To protect backward compatibility, explicitly alias one of these using the `--resource-name-alias` CLI parameter.

Root Cause Analysis

The bug exists in the hand-off between api.py and wrappers.py.

File-level resources bypass the standard _load_message pipeline where CLI aliases are normally injected. Instead, they are parsed in api.py inside the Proto.resource_messages property, which relies on wrappers.CommonResource.build(res) to spin up a dummy MessageType.

API client name and version

No response

Reproduction steps: code

file: main.py

   def reproduce():
    # complete code here

Reproduction steps: supporting files

file: mydata.csv

alpha,1,3
beta,2,5

Reproduction steps: actual results

file: output.txtmydata.csv

Calculated: foo

Reproduction steps: expected results

file: output.txtmydata.csv

Calculated: bar

OS & version + platform

No response

Python environment

No response

Python dependencies

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.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