-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
list_subscriptions does not work properly #1485
Comments
👍 |
@tseaver subscription, next_page_tokens = client.list_subscriptions(topic_name = 'topic_name') It does not work. And the issue is this line: subscriptions = [Subscription.from_api_repr(resource, self,
topics=topics)
for resource in resp.get('subscriptions', ())] The code pass an empty value of resource (maybe) to subscriptions. The output is like: >>> from gcloud import pubsub
>>> client = pubsub.Client(project = 'my_project'')
>>> client.list_subscriptions(topic_name = 'my_topic')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gcloud/pubsub/client.py", line 131, in list_subscriptions
for resource in resp['subscriptions']]
File "/usr/local/lib/python2.7/dist-packages/gcloud/pubsub/subscription.py", line 68, in from_api_repr
topic_path = resource['topic']
TypeError: string indices must be integers |
@tseaver Have you reproduced? |
@tseaver I reproduced: >>> import gcloud.pubsub
>>> from gcloud import _helpers
>>> from gcloud.environment_vars import TESTS_PROJECT
>>> _helpers.PROJECT = TESTS_PROJECT
>>> C = gcloud.pubsub.Client()
>>> C.project
'FOOOBAR'
>>> C.list_subscriptions()
([], None)
>>> C.list_topics()
([], None)
>>> T = C.topic('hi-mom')
>>> T.create()
>>> S = T.subscription('this-is-mine')
>>> S.create()
>>> C.list_topics()
([<gcloud.pubsub.topic.Topic object at 0x7f7c21812310>], None)
>>> C.list_subscriptions()
([<gcloud.pubsub.subscription.Subscription object at 0x7f7c21812390>], None)
>>> C.list_subscriptions(topic_name=T.name)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "gcloud/pubsub/client.py", line 131, in list_subscriptions
for resource in resp.get('subscriptions', ())]
File "gcloud/pubsub/subscription.py", line 71, in from_api_repr
topic_path = resource['topic']
TypeError: string indices must be integers |
In [16]: %debug
> .../gcloud-python/gcloud/pubsub/subscription.py(71)from_api_repr()
69 if topics is None:
70 topics = {}
---> 71 topic_path = resource['topic']
72 topic = topics.get(topic_path)
73 if topic is None:
ipdb> resource
u'projects/omega-moonlight-697/subscriptions/this-is-mine'
ipdb> u
> .../gcloud-python/gcloud/pubsub/client.py(131)list_subscriptions()
129 subscriptions = [Subscription.from_api_repr(resource, self,
130 topics=topics)
--> 131 for resource in resp.get('subscriptions', ())]
132 return subscriptions, resp.get('nextPageToken')
133
ipdb> resp
{u'subscriptions': [u'projects/omega-moonlight-697/subscriptions/this-is-mine']} |
This is in contrast to what the output looks like without the topic name: {
"subscriptions": [
{
"topic": "projects/omega-moonlight-697/topics/hi-mom",
"ackDeadlineSeconds": 10,
"pushConfig": {},
"name": "projects/omega-moonlight-697/subscriptions/this-is-mine"
}
]
} |
OK, I see the issue: The API design choice here is utterly bogus, but we have to work around it. |
Given the disparity, I would prefer to handle topic-based subscriptions by adding a |
@bitcpf Thanks for the report! |
👍 with separate methods @tseaver |
list_subscriptions()
works butlist_subscriptions(topic_name = 'topic_name')
does not work properlyThe text was updated successfully, but these errors were encountered: