Skip to content

Commit b2703db

Browse files
authored
Merge pull request #67 from arenadata/fix_duplicated_fields
Removed query and form parameters if they exist in path parameters
2 parents f25503b + 017045b commit b2703db

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

adcm_client/wrappers/api.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,24 @@ def action(self, *args, **kwargs):
133133
Example:
134134
api.action(['cluster', 'create'], name='testcluster')
135135
"""
136-
overrides = None
137-
138-
if args[0][-1] == 'list':
139-
# Removing query parameters if they exist in path parameters
140-
path = args[0]
141-
link = self.schema[path[0]]
142-
for item in path[1:]:
143-
link = link[item]
144-
145-
fields = []
146-
path_fields = [field.name for field in link.fields if field.location == 'path']
147-
for field in link.fields:
148-
if not (field.location == 'query' and field.name in path_fields):
149-
fields.append(field)
150-
fields = tuple(fields)
151-
overrides = {'fields': fields}
136+
137+
# After parsing the schema, fields for a query, a form, or a path may appear that have
138+
# the same names, which may cause the field value to go to the wrong place.
139+
# Path fields take precedence over query and form fields, so if there are path fields
140+
# and query or form fields with the same name, we delete the query and form fields
141+
# with the given name.
142+
path = args[0]
143+
link = self.schema[path[0]]
144+
for item in path[1:]:
145+
link = link[item]
146+
147+
fields = []
148+
path_fields = [field.name for field in link.fields if field.location == 'path']
149+
for field in link.fields:
150+
if not (field.location in ('query', 'form') and field.name in path_fields):
151+
fields.append(field)
152+
fields = tuple(fields)
153+
overrides = {'fields': fields}
152154

153155
data = self.client.action(self.schema, *args, overrides=overrides, **kwargs)
154156
self._check_for_error(data)

0 commit comments

Comments
 (0)