You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PubSub Client: list_subscriptions returns all subscriptions, not just for that topic #4426
Python version and virtual environment information python --version
Python 3.6.3
google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze
google==1.9.3
google-api-core==0.1.1
google-auth==1.2.1
google-cloud-core==0.28.0
google-cloud-pubsub==0.29.0
google-gax==0.15.16
googleapis-common-protos==1.5.3
grpc-google-iam-v1==0.11.4
deflist_subscriptions_in_topic(project, topic_name):
"""Lists all subscriptions for a given topic."""subscriber=pubsub_v1.SubscriberClient()
topic_path=subscriber.topic_path(project, topic_name)
forsubscriptioninsubscriber.list_subscriptions(topic_path):
print(subscription.name)
topic path being used as shown by topic_path = subscriber.topic_path(project, topic_name): projects/my-team-dev/topics/testing-topic
changed the title [-]PubSub Client: List Subscriptions returns all subscriptions, not just for that topic[/-][+]PubSub Client: list_subscriptions returns all subscriptions, not just for that topic[/+]on Nov 20, 2017
+1
I'm seeing this also, on google-cloud-pubsub:0.29.0, google-cloud:0.30.0
If the topic_path doesn't adhere to the form projects/project/topics/topic, then an exception is caught, but if it's projects/project/topics/some-topic-name-that-doesnt-exist, then all subscriptions for all topics are listed.
So this is an issue, but not really as reported. The problem is that subscriber.list_subscriptions() is meant to be for the entire project:
In [1]: importgoogle.authIn [2]: fromgoogle.cloudimportpubsub_v1In [3]: _, project=google.auth.default()
In [4]: publisher=pubsub_v1.PublisherClient()
E121514:50:02.43397943011896ev_epollex_linux.cc:1482] SkippingepollexbecuaseGRPC_LINUX_EPOLLisnotdefined.
E121514:50:02.43401351411896ev_epoll1_linux.cc:1261] Skippingepoll1becuaseGRPC_LINUX_EPOLLisnotdefined.
E121514:50:02.43402095611896ev_epollsig_linux.cc:1761] SkippingepollsigbecuaseGRPC_LINUX_EPOLLisnotdefined.
In [5]: subscriber=pubsub_v1.SubscriberClient()
In [6]: subscriber.list_subscriptions?
Signature: subscriber.list_subscriptions(project, ...)
Docstring:
Listsmatchingsubscriptions.
...
Args:
project (str): Thenameofthecloudprojectthatsubscriptionsbelongto.
Formatis``projects/{project}``.
...
In [7]: project_path=subscriber.project_path(project)
In [8]: LS=list(subscriber.list_subscriptions(project_path))
In [9]: len(LS)
Out[9]: 6
The method you want is publisher.list_topic_subscriptions:
In [10]: topic_path=publisher.topic_path(project, 'abcdef2')
In [11]: LTS=list(publisher.list_topic_subscriptions(topic_path))
In [12]: len(LTS)
Out[12]: 3In [13]: publisher.list_topic_subscriptions?
Signature: publisher.list_topic_subscriptions(topic, ...)
Docstring:
Liststhenameofthesubscriptionsforthistopic.
...
Args:
topic (str): Thenameofthetopicthatsubscriptionsareattachedto.
Formatis``projects/{project}/topics/{topic}``.
The actual issue is that subscriber.list_subscriptions doesn't reject requests with the topic path (likely because the topic path starts with the project path):
In [14]: topic_path.startswith(project_path)
Out[14]: TrueIn [15]: LS_ALSO=list(subscriber.list_subscriptions(topic_path))
In [16]: LS_ALSO==LSOut[16]: True
I think an issue could be filed with the backend to reject those requests with the topic_path where a project_path should be.
Activity
[-]PubSub Client: List Subscriptions returns all subscriptions, not just for that topic[/-][+]PubSub Client: list_subscriptions returns all subscriptions, not just for that topic[/+]gylu commentedon Nov 20, 2017
+1
I'm seeing this also, on
google-cloud-pubsub:0.29.0,google-cloud:0.30.0If the topic_path doesn't adhere to the form
projects/project/topics/topic, then an exception is caught, but if it'sprojects/project/topics/some-topic-name-that-doesnt-exist, then all subscriptions for all topics are listed.dhermes commentedon Dec 15, 2017
So this is an issue, but not really as reported. The problem is that
subscriber.list_subscriptions()is meant to be for the entire project:The method you want is
publisher.list_topic_subscriptions:The actual issue is that
subscriber.list_subscriptionsdoesn't reject requests with the topic path (likely because the topic path starts with the project path):I think an issue could be filed with the backend to reject those requests with the
topic_pathwhere aproject_pathshould be./cc @kir-titievsky
dhermes commentedon Dec 15, 2017
I filed https://issuetracker.google.com/issues/70727179 with the backend team.
anorth2 commentedon Jan 8, 2018
@dhermes If this is indeed the issue, then this needs to be updated: https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/pubsub/cloud-client/subscriber.py#L30
The docs state that my method was the way to retrieve by topic.
https://cloud.google.com/pubsub/docs/admin#pubsub-list-subscriptions-python
dhermes commentedon Jan 8, 2018
Thanks for finding that @anorth2 (I'm only loosely aware of what's in
python-docs-samples). I filed GoogleCloudPlatform/python-docs-samples#1305 against that repo.chore(deps): update dependency google-cloud-translate to v2.0.2 [(#4426…