Skip to content

Commit c61bdad

Browse files
authored
Deal with empty and bad dataset names (#314)
ServiceX no longer returns a *Fatal* error when it is asked to look up a bad dataset name or a dataset name that has zero files. * Detect a completed transform with no files Fixes #313 Fixes #312
1 parent 9341628 commit c61bdad

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

servicex/servicex_adaptor.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ async def get_transform_status(
210210
f"Transform status for {request_id}" ' is marked "Fatal".'
211211
)
212212

213+
if (
214+
"status" in info
215+
and info["status"] == "Complete"
216+
and info["files-remaining"] is None
217+
and info["files-processed"] == 0
218+
):
219+
raise ServiceXFatalTransformException(
220+
f"Transform status for {request_id}"
221+
' is marked "Complete" but no files were processed. Either the dataset '
222+
"is empty, or the dataset name is invalid."
223+
)
224+
213225
files_remaining = self._get_transform_stat(info, "files-remaining")
214226
files_failed = self._get_transform_stat(info, "files-skipped")
215227
files_processed = self._get_transform_stat(info, "files-processed")

tests/test_servicex_adaptor.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ def servicex_status_negative(mocker):
9898
)
9999

100100

101+
@pytest.fixture
102+
def servicex_no_files(mocker):
103+
"Returns a result when there are no files in the dataset"
104+
result = {
105+
"files-processed": 0,
106+
"files-remaining": None,
107+
"files-skipped": 0,
108+
"request-id": "24e59fa2-e1d7-4831-8c7e-82b2efc7c658",
109+
"stats": None,
110+
"status": "Complete",
111+
}
112+
mocker.patch(
113+
"aiohttp.ClientSession.get",
114+
return_value=ClientSessionMocker(dumps(result), 200),
115+
)
116+
117+
101118
@pytest.fixture
102119
def good_submit(mocker):
103120
client = mocker.MagicMock()
@@ -191,7 +208,6 @@ async def test_status_no_auth(servicex_status_request):
191208

192209
@pytest.mark.asyncio
193210
async def test_status_fatal_status(servicex_status_fatal):
194-
195211
sa = ServiceXAdaptor("http://localhost:500/sx")
196212
async with aiohttp.ClientSession() as client:
197213
with pytest.raises(ServiceXFatalTransformException) as e:
@@ -202,7 +218,6 @@ async def test_status_fatal_status(servicex_status_fatal):
202218

203219
@pytest.mark.asyncio
204220
async def test_status_negative_status(servicex_status_negative):
205-
206221
sa = ServiceXAdaptor("http://localhost:500/sx")
207222
async with aiohttp.ClientSession() as client:
208223
with pytest.raises(ServiceXFatalTransformException) as e:
@@ -211,6 +226,16 @@ async def test_status_negative_status(servicex_status_negative):
211226
assert "negative" in str(e.value)
212227

213228

229+
@pytest.mark.asyncio
230+
async def test_status_empty(servicex_no_files):
231+
sa = ServiceXAdaptor("http://localhost:500/sx")
232+
async with aiohttp.ClientSession() as client:
233+
with pytest.raises(ServiceXFatalTransformException) as e:
234+
await sa.get_transform_status(client, "123-123-123-444")
235+
236+
assert "empty" in str(e.value)
237+
238+
214239
@pytest.mark.asyncio
215240
async def test_status_with_auth(mocker):
216241
client = mocker.MagicMock()
@@ -243,7 +268,6 @@ async def test_status_with_auth(mocker):
243268

244269
@pytest.mark.asyncio
245270
async def test_status_unknown_request(servicex_status_unknown):
246-
247271
sa = ServiceXAdaptor("http://localhost:5000/sx")
248272
with pytest.raises(ServiceXUnknownRequestID) as e:
249273
async with aiohttp.ClientSession() as client:

0 commit comments

Comments
 (0)