Skip to content

PubSub Client: list_subscriptions returns all subscriptions, not just for that topic #4426

Closed

Description

@anorth2
  1. OS type and version
    Any and all

  2. Python version and virtual environment information python --version
    Python 3.6.3

  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

  4. Stacktrace if available

  5. Steps to reproduce
    Run example code for listing subscriptions for a topic from here:
    https://cloud.google.com/pubsub/docs/admin

  6. Code example

def list_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)

    for subscription in subscriber.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

Using GitHub flavored markdown can help make your request clearer.
See: https://guides.github.com/features/mastering-markdown/

Activity

  1. 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
  2. added
    api: pubsubIssues related to the Pub/Sub API.
    status: investigatingThe issue is under investigation, which is determined to be non-trivial.
    on Nov 20, 2017
  3. gylu commented on Nov 20, 2017

    @gylu

    +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.

  4. dhermes commented on Dec 15, 2017

    @dhermes
    Contributor

    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]: import google.auth
    
    In [2]: from google.cloud import pubsub_v1
    
    In [3]: _, project = google.auth.default()
    
    In [4]: publisher = pubsub_v1.PublisherClient()
    E1215 14:50:02.433979430   11896 ev_epollex_linux.cc:1482]   Skipping epollex becuase GRPC_LINUX_EPOLL is not defined.
    E1215 14:50:02.434013514   11896 ev_epoll1_linux.cc:1261]    Skipping epoll1 becuase GRPC_LINUX_EPOLL is not defined.
    E1215 14:50:02.434020956   11896 ev_epollsig_linux.cc:1761]  Skipping epollsig becuase GRPC_LINUX_EPOLL is not defined.
    
    In [5]: subscriber = pubsub_v1.SubscriberClient()
    
    In [6]: subscriber.list_subscriptions?
    Signature: subscriber.list_subscriptions(project, ...)
    Docstring:
    Lists matching subscriptions.
    
    ...
    
    Args:
        project (str): The name of the cloud project that subscriptions belong to.
            Format is ``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]: 3
    
    In [13]: publisher.list_topic_subscriptions?
    Signature: publisher.list_topic_subscriptions(topic, ...)
    Docstring:
    Lists the name of the subscriptions for this topic.
    
    ...
    
    Args:
        topic (str): The name of the topic that subscriptions are attached to.
            Format is ``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]: True
    
    In [15]: LS_ALSO = list(subscriber.list_subscriptions(topic_path))
    
    In [16]: LS_ALSO == LS
    Out[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.

    /cc @kir-titievsky

  5. dhermes commented on Dec 15, 2017

    @dhermes
    Contributor
  6. anorth2 commented on Jan 8, 2018

    @anorth2
    Author
  7. dhermes commented on Jan 8, 2018

    @dhermes
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub API.status: investigatingThe issue is under investigation, which is determined to be non-trivial.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions