Skip to content

Commit ccdfbff

Browse files
zehausertheacodes
authored andcommitted
Fix filter_params argument in list_projects (googleapis#5383)
The filter_params parameter of resource_manager.Client.list_projects is a dict (of properties to filter on and the desired value for each property). Prior to this commit, this dict was passed into the HTTPIterator constructor in extra_params['filter']. This didn't work, because extra_params values can't be dicts. They *can* be iterables, but since the iterable of a dict is its keys, this resulted in only the properties being sent along in the 'filter' query param, while the desired values for those properties were discarded. This commit transforms the filter_params dict into a simple list prior to shoving it in extra_params, which fixes the bug.
1 parent 1f8f485 commit ccdfbff

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

resource_manager/google/cloud/resource_manager/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
"""A Client for interacting with the Resource Manager API."""
1616

17+
import six
1718

1819
from google.api_core import page_iterator
1920
from google.cloud.client import Client as BaseClient
@@ -162,7 +163,10 @@ def list_projects(self, filter_params=None, page_size=None):
162163
extra_params['pageSize'] = page_size
163164

164165
if filter_params is not None:
165-
extra_params['filter'] = filter_params
166+
extra_params['filter'] = [
167+
'{}:{}'.format(key, value)
168+
for key, value in six.iteritems(filter_params)
169+
]
166170

167171
return page_iterator.HTTPIterator(
168172
client=self,

resource_manager/tests/unit/test_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,13 @@ def test_list_projects_with_filter(self):
217217
self.assertEqual(project.status, STATUS)
218218

219219
# Check that the filter made it in the request.
220+
FLATTENED_FILTER_PARAMS = ['id:project-id']
220221
request, = client._connection._requested
221222
self.assertEqual(request, {
222223
'path': '/projects',
223224
'method': 'GET',
224225
'query_params': {
225-
'filter': FILTER_PARAMS,
226+
'filter': FLATTENED_FILTER_PARAMS,
226227
},
227228
})
228229

0 commit comments

Comments
 (0)