Skip to content

Commit 367bdc2

Browse files
committed
PE-27800 - Under certain conditions the response body can get printed more than once
1 parent 1a6c0d3 commit 367bdc2

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

planet/scripts/util.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,26 @@ def echo_json_response(response, pretty, limit=None, ndjson=False):
171171
sort_keys = True
172172
nl = True
173173
try:
174-
if ndjson and hasattr(response, 'items_iter'):
174+
if hasattr(response, 'items_iter'):
175175
items = response.items_iter(limit)
176-
for item in items:
177-
click.echo(json.dumps(item))
176+
if ndjson:
177+
for item in items:
178+
click.echo(json.dumps(item))
179+
else:
180+
click.echo(json.dumps(list(items)))
178181
elif not ndjson and hasattr(response, 'json_encode'):
179182
response.json_encode(click.get_text_stream('stdout'), limit=limit,
180183
indent=indent, sort_keys=sort_keys)
181-
182-
res = response.get_raw()
183-
if len(res) == 0: # if the body is empty, just return the status
184-
click.echo("status: {}".format(response.response.status_code))
185184
else:
186-
res = json.dumps(json.loads(res), indent=indent,
187-
sort_keys=sort_keys)
188-
click.echo(res)
189-
if nl:
190-
click.echo()
185+
res = response.get_raw()
186+
if len(res) == 0: # if the body is empty, just return the status
187+
click.echo("status: {}".format(response.response.status_code))
188+
else:
189+
res = json.dumps(json.loads(res), indent=indent,
190+
sort_keys=sort_keys)
191+
click.echo(res)
192+
if nl:
193+
click.echo()
191194
except IOError as ioe:
192195
# hide scary looking broken pipe stack traces
193196
raise click.ClickException(str(ioe))

0 commit comments

Comments
 (0)