Skip to content
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

Don't error out in rma_all for incomplete response #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/atldld/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,29 @@ def rma_all(rma_parameters: RMAParameters) -> list:
f'Expected total_rows to be {total_rows} but got {status["total_rows"]}'
)

# Each new request should yield new data. If no data was received, then
# something must have gone wrong.
# We haven't got all the rows yet, but the query yielded zero results.
# This could be due to an arbitrary server-side problem, but we know
# of at least one query for which the number of returned results is
# consistently smaller than the number of reported results:
# RMAParameters(
# "SectionDataSet",
# criteria={
# "specimen": {"donor": {"age": {"days": 56}}},
# "probes": {"orientation": {"name": "Antisense"}}
# },
# )
# this gives total_rows=50476 but len(msg)=50274.
# Previously we would raise an error when this happened, but since this
# is reproducible we now only print a warning.
if status["num_rows"] == 0:
raise RuntimeError("No data received")
break

pos += status["num_rows"]
msg += new_msg

if not len(msg) == total_rows:
logger.warning("The server sent only %d of %d results", len(msg), total_rows)

return msg


Expand Down
9 changes: 6 additions & 3 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging
import re

import pytest
Expand Down Expand Up @@ -241,7 +242,7 @@ def test_inconsistent_total_rows(self):
rma_all(params)

@responses.activate
def test_no_data_received(self):
def test_incomplete_data_received(self, caplog):
params = RMAParameters("my-model")
# Can at most fetch 25_000 in one request
msg = list(range(26_000))
Expand All @@ -259,12 +260,14 @@ def test_no_data_received(self):
"success": True,
"id": 0,
"start_row": len(msg_1),
"num_rows": 0, # this should always be greater than 0
"num_rows": 0, # this should normally always be greater than 0
"total_rows": len(msg),
"msg": msg_2,
}
responses.add(responses.GET, re.compile(""), json=return_json_1)
responses.add(responses.GET, re.compile(""), json=return_json_2)

with pytest.raises(RuntimeError, match="No data received"):
with caplog.at_level(logging.WARNING, logger="atldld.requests"):
rma_all(params)

assert "The server sent only" in caplog.text