GeezerVison is showing github.com — Handle subscription list for specific topic separately. by andrazhribernik · Pull Request #1411 · googleapis/google-cloud-python
Conversation
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
📝 Please visit https://cla.developers.google.com/ to sign.
Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.
- If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
- If you signed the CLA as a corporation, please let us know the company's name.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Handle subscription list for specific topic separately.
|
Thanks for the PR!
Not sure I understand what's happening here. Can you share a bit more about what you're trying to do? And maybe add some tests?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Sorry for not adding any description and tests. It is basically a bug fix.
When we tried to use this functionality:
from gcloud import pubsub
client = pubsub.Client(project=<project_name>)
client.list_subscriptions(topic_name=<topic_name>)
we got the following error.
TypeError Traceback (most recent call last)
<ipython-input-3-8be845bada22> in <module>()
----> 1 client.list_subscriptions(topic_name="test_aw_2")
/Users/andrazhribernik/cytora/gcloud-python/gcloud/pubsub/client.py in list_subscriptions(self, page_size, page_token, topic_name)
129 subscriptions = [Subscription.from_api_repr(resource, self,
130 topics=topics)
--> 131 for resource in resp['subscriptions']]
132 return subscriptions, resp.get('nextPageToken')
133
/Users/andrazhribernik/cytora/gcloud-python/gcloud/pubsub/subscription.pyc in from_api_repr(cls, resource, client, topics)
66 if topics is None:
67 topics = {}
---> 68 topic_path = resource['topic']
69 topic = topics.get(topic_path)
70 if topic is None:
TypeError: string indices must be integers
It also fails with different error if param topic_name is not specified
from gcloud import pubsub
client = pubsub.Client(project=<project_name>)
client.list_subscriptions()
returns
ValueError Traceback (most recent call last)
<ipython-input-4-39df795327d3> in <module>()
----> 1 client.list_subscriptions()
/Users/andrazhribernik/cytora/gcloud-python/gcloud/pubsub/client.py in list_subscriptions(self, page_size, page_token, topic_name)
129 subscriptions = [Subscription.from_api_repr(resource, self,
130 topics=topics)
--> 131 for resource in resp['subscriptions']]
132 return subscriptions, resp.get('nextPageToken')
133
/Users/andrazhribernik/cytora/gcloud-python/gcloud/pubsub/subscription.pyc in from_api_repr(cls, resource, client, topics)
71 # NOTE: This duplicates behavior from Topic.from_api_repr to avoid
72 # an import cycle.
---> 73 topic_name = topic_name_from_path(topic_path, client.project)
74 topic = topics[topic_path] = client.topic(topic_name)
75 _, _, _, name = resource['name'].split('/')
/Users/andrazhribernik/cytora/gcloud-python/gcloud/pubsub/_helpers.pyc in topic_name_from_path(path, project)
36 if (len(path_parts) != 4 or path_parts[0] != 'projects' or
37 path_parts[2] != 'topics'):
---> 38 raise ValueError('Expected path to be of the form '
39 'projects/{project}/topics/{topic_name}')
40 if (len(path_parts) != 4 or path_parts[0] != 'projects' or
ValueError: Expected path to be of the form projects/{project}/topics/{topic_name}
The code we implemented basically solve a problem with inconsistency of GCloud REST API. It worked for us and was very quick fix. If you think this should be solved in a different way, I would be happy to hear your ideas.
I just took a look on tests now and it seems that tests do not reflect the output from GCloud REST API.
GCloud REST API response for a specific topic does not return a list of format [{'name': SUB_PATH, 'topic': TOPIC_PATH}], but returns list of strings (['topic1 name', 'topic2 name', ...]). It also seems pagination is on by default, which is not reflected in tests.
I am wondering. Is there a bug on GCLOUD REST API or on the gcloud-python side. If you think that this needs to be fix, I can refactor tests as well.
I hope it is clearer now. If you need any more informations, please do not hesitate to ask me.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
/cc @tseaver : This seems like a legit concern. Curious why our system tests don't catch this?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@andrazhribernik can you supply the value of resource when the tracebacks are raised? I'm having a hard time following the logic for your changes.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@tseaver Value of resource is different whether param 'topic_name' is specified or not.
topic_name is not specified
from gcloud import pubsub
client = pubsub.Client(project=<project_name>)
client.list_subscriptions()
Error is raised, if there is any subscription for a topic that has already been deleted (_deleted-topic_).
Sample value of resp object:
{u'subscriptions': [
{
u'topic': u'projects/<project_id>/topics/<topic_name>',
u'ackDeadlineSeconds': 10,
u'pushConfig': {},
u'name': u'projects//<project_id>/subscriptions//<subscription_name>''
},
{
u'topic': u'_deleted-topic_',
u'ackDeadlineSeconds': 10,
u'pushConfig': {},
u'name': u'projects/<project_id>/subscriptions/<subscription_name>'
},
topic_name is specified
from gcloud import pubsub
client = pubsub.Client(project=<project_name>)
client.list_subscriptions(topic_name=<topic_name>)
Error is raised for every request of this type.
Sample value of resp object:
{u'subscriptions': [
u'projects/<project_id>/subscriptions/<subscription_name1>',
u'projects/<project_id>/subscriptions/<subscription_name2>'
]
}
I hope this explanation will help to understand my code updates.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@andrazhribernik I believe that #1440 should address this issue. @jgeewax, it also adds a system test for list_subscriptions (adding one for the list_topics case is too hard, as there is no guarantee that a given project will have no topics at all).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
parthea
pushed a commit
that referenced
this pull request
Nov 24, 2025
This allows generator users to set the numeric-enum-response parameter at generation time via the BUILD rule. The default is `False` for backward compatibility.
parthea
pushed a commit
that referenced
this pull request
Mar 2, 2026
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Andrew Browne <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
cla: no
This human has *not* signed the Contributor License Agreement.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|