GeezerVison is showing github.com — Resource patterns with wildcard '*' results in failing test for parse_path · Issue #701 · googleapis/gapic-generator-python
This repository was archived by the owner on Aug 25, 2026. It is now read-only.
This repository was archived by the owner on Aug 25, 2026. It is now read-only.
Resource patterns with wildcard '*' results in failing test for parse_path #701
Labels
🚨This issue needs some love.priority: p2Moderately-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. Description
Asset has a resource path annotated with pattern *
https://github.com/googleapis/googleapis/blob/f1e0ce4dbc5f59448f441093014d712af442984f/google/cloud/asset/v1/assets.proto#L96-L100
message Asset {
option (google.api.resource) = {
type: "cloudasset.googleapis.com/Asset"
pattern: "*"
};
This results in a unhelpful set of resource name helpers:
@staticmethod
def asset_path() -> str:
"""Return a fully-qualified asset string."""
return "*".format()
@staticmethod
def parse_asset_path(path: str) -> Dict[str, str]:
"""Parse a asset path into its component segments."""
m = re.match(r"^*$", path)
return m.groupdict() if m else {}
The generated tests break because of the *.
def test_asset_path():
expected = "*".format()
actual = AssetServiceClient.asset_path()
assert expected == actual
def test_parse_asset_path():
expected = {}
path = AssetServiceClient.asset_path(**expected)
# Check that the path construction is reversible.
actual = AssetServiceClient.parse_asset_path(path)
assert expected == actual
if not item or item[0][0] is AT:
> raise source.error("nothing to repeat",
source.tell() - here + len(this))
E re.error: nothing to repeat at position 1
../../.pyenv/versions/3.8.1/lib/python3.8/sre_parse.py:668: error
The * pattern is uncommon and this method isn't actually helpful for parsing paths. I'm planning on deleting it from the generated output for now.
Activity
added
type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2Moderately-important priority. Fix may not be included in next release. and removed
on Dec 1, 2020changed the title
[-]Resource pattern '*' results in failing test for parse_path[/-] [+]Resource patterns with wildcard '*' results in failing test for parse_path[/+] on Dec 29, 2020busunkim96 commented on Dec 29, 2020
ContributorAuthor
More actions
Similar issue with monitoring which has a path with **.
https://github.com/googleapis/googleapis/blob/69697504d9eba1d064820c3085b4750767be6d08/google/monitoring/v3/metric_service.proto#L39-L46
option (google.api.resource_definition) = {
type: "monitoring.googleapis.com/MetricDescriptor"
pattern: "projects/{project}/metricDescriptors/{metric_descriptor=**}"
pattern: "organizations/{organization}/metricDescriptors/{metric_descriptor=**}"
pattern: "folders/{folder}/metricDescriptors/{metric_descriptor=**}"
pattern: "*"
history: ORIGINALLY_SINGLE_PATTERN
};
def metric_descriptor_path(project: str,) -> str:
"""Return a fully-qualified metric_descriptor string."""
return "projects/{project}/metricDescriptors/{metric_descriptor=**}".format(
project=project,
)
@staticmethod
def parse_metric_descriptor_path(path: str) -> Dict[str, str]:
"""Parse a metric_descriptor path into its component segments."""
m = re.match(
r"^projects/(?P<project>.+?)/metricDescriptors/{metric_descriptor=**}$",
path,
)
return m.groupdict() if m else {}
def test_metric_descriptor_path():
project = "squid"
expected = "projects/{project}/metricDescriptors/{metric_descriptor=**}".format(
project=project,
)
actual = MetricServiceClient.metric_descriptor_path(project)
assert expected == actual
def test_parse_metric_descriptor_path():
expected = {
"project": "clam",
}
path = MetricServiceClient.metric_descriptor_path(**expected)
# Check that the path construction is reversible.
actual = MetricServiceClient.parse_metric_descriptor_path(path)
assert expected == actualadded
🚨This issue needs some love. and removed
🚨This issue needs some love. on Mar 30, 2021vam-google commented on Jan 19, 2022
busunkim96 commented on Jan 20, 2022
ContributorAuthor
More actions
Metadata
Metadata
🚨This issue needs some love.priority: p2Moderately-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. Development
No branches or pull requestsIssue actions