Skip to content

Commit bfacd73

Browse files
authored
Merge pull request #3159 from antgonza/fix-Overflow-download-analysis-metadata
fix Overflow in download analysis metadata
2 parents b648221 + 3635b06 commit bfacd73

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

qiita_db/handlers/analysis.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
# The full license is in the file LICENSE, distributed with this software.
77
# -----------------------------------------------------------------------------
88

9+
from tornado import gen
910
from tornado.web import HTTPError
11+
from json import dumps
1012

1113
import qiita_db as qdb
1214
from .oauth2 import OauthBaseHandler, authenticate_oauth
@@ -44,7 +46,7 @@ def _get_analysis(a_id):
4446

4547
class APIAnalysisMetadataHandler(OauthBaseHandler):
4648
@authenticate_oauth
47-
def get(self, analysis_id):
49+
async def get(self, analysis_id):
4850
"""Retrieves the analysis metadata
4951
5052
Parameters
@@ -56,15 +58,37 @@ def get(self, analysis_id):
5658
-------
5759
dict
5860
The contents of the analysis keyed by sample id
61+
62+
Notes
63+
-----
64+
This response needed to be broken in chunks because we were hitting
65+
the max size of a respose: 2G; based on: https://bit.ly/3CPvyjd
5966
"""
67+
chunk_len = 1024 * 1024 * 1 # 1 MiB
68+
69+
response = None
6070
with qdb.sql_connection.TRN:
6171
a = _get_analysis(analysis_id)
6272
mf_fp = qdb.util.get_filepath_information(
6373
a.mapping_file)['fullpath']
64-
response = None
6574
if mf_fp is not None:
6675
df = qdb.metadata_template.util.load_template_to_dataframe(
6776
mf_fp, index='#SampleID')
68-
response = df.to_dict(orient='index')
77+
response = dumps(df.to_dict(orient='index'))
78+
79+
if response is not None:
80+
crange = range(chunk_len, len(response)+chunk_len, chunk_len)
81+
for i, (win) in enumerate(crange):
82+
# sending the chunk and flushing
83+
chunk = response[i*chunk_len:win]
84+
self.write(chunk)
85+
await self.flush()
86+
87+
# cleaning chuck and pause the coroutine so other handlers
88+
# can run, note that this is required/important based on the
89+
# original implementation in https://bit.ly/3CPvyjd
90+
del chunk
91+
await gen.sleep(0.000000001) # 1 nanosecond
6992

70-
self.write(response)
93+
else:
94+
self.write(None)

scripts/qiita-test-install

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ class QiitaConfig(TestCase):
232232
string_acceptable_version))
233233

234234
def test_redbiom_version(self):
235-
acceptable_version = (0, 3, 5)
235+
acceptable_version = (0, 3, 8)
236236
string_acceptable_version = '.'.join(map(str, acceptable_version))
237237
version = tuple(map(int, redbiom_lib_version.split('.')))
238238

239-
self.assertTrue(acceptable_version == version,
239+
self.assertTrue(acceptable_version >= version,
240240
'Unsupported redbiom version. You have %s but the '
241241
'minimum required version is %s'
242242
% ('.'.join(map(str, version)),

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
install_requires=['psycopg2', 'click', 'bcrypt', 'pandas',
106106
'biom-format', 'tornado<6.0', 'toredis', 'redis',
107107
'scp', 'pyparsing', 'h5py', 'natsort', 'nose', 'pep8',
108-
'networkx', 'humanize', 'scikit-bio', 'wtforms',
108+
'networkx', 'humanize', 'scikit-bio', 'wtforms<3.0.0',
109109
'openpyxl', 'sphinx-bootstrap-theme', 'Sphinx', 'nltk',
110110
'gitpython', 'redbiom', 'pyzmq', 'sphinx_rtd_theme',
111111
'paramiko', 'seaborn', 'matplotlib', 'scipy', 'nose',

0 commit comments

Comments
 (0)