Skip to content

Commit

Permalink
More tweakies ...
Browse files Browse the repository at this point in the history
So, forget I even thought about dealing with the `MetadataError` here. I can't
collect "errors" here because `_get_dataset_metadata` actually internally
traps any "real" metadata error and returns a `None` value already. To collect
a list of keyspace errors I'd need to change `_get_dataset_metadata`, and I'm
not going to do that here.

The only `MetadataError` that can get through here is actually a bad keyname,
and we've already done that validation so we really don't need to worry about
it.

I'd like to revise this separately because I've realized that while I allow
`filter` to reference the weird non-alphanumeric key paths in `metalog`, I
didn't do that for the `metadata` parameter... and that'll affect the
`_get_dataset_metadata` as well because it independently validates the key
paths and wouldn't know about that exception. (Ugh.) Not here. I did however
add a test case showing that a keyspace conflict error results in a `None`
value.
  • Loading branch information
dbutenhof committed Mar 16, 2023
1 parent 0c135d6 commit 093d72b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/pbench/server/api/resources/datasets_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,18 @@ def datasets(self, request: Request, json: JSONOBJECT, query: Query) -> JSONOBJE
keys = json.get("metadata")

response = []
errors = []
for dataset in datasets:
d = {
"name": dataset.name,
"resource_id": dataset.resource_id,
}
try:
d["metadata"] = self._get_dataset_metadata(dataset, keys)
except MetadataError as e:
errors.append(str(e))
except MetadataError:
d["metadata"] = None
response.append(d)

paginated_result["results"] = response
if errors:
paginated_result["errors"] = errors
return paginated_result

def _get(
Expand Down
37 changes: 37 additions & 0 deletions lib/pbench/test/unit/server/test_datasets_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,43 @@ def test_get_bad_keys(self, query_as):
)
}

def test_get_get_errors(self, server_config, query_as):
"""Test case reporting key errors
Args:
query_as: Query helper fixture
"""
fio_1 = Dataset.query(name="fio_1")
fio_2 = Dataset.query(name="fio_2")
Metadata.setvalue(dataset=fio_1, key="global.test", value="ABC")
Metadata.setvalue(dataset=fio_2, key="global.test.foo", value="ABC")
response = query_as(
{"metadata": "global.test.foo"},
"drb",
HTTPStatus.OK,
)
assert response.json == {
"next_url": "",
"results": [
{
"metadata": {"global.test.foo": None},
"name": "drb",
"resource_id": "random_md5_string1",
},
{
"metadata": {"global.test.foo": None},
"name": "fio_1",
"resource_id": "random_md5_string3",
},
{
"metadata": {"global.test.foo": "ABC"},
"name": "fio_2",
"resource_id": "random_md5_string4",
},
],
"total": 3,
}

def test_get_unknown_keys(self, query_as):
"""Test case requesting non-existent query parameter keys.
Expand Down

0 comments on commit 093d72b

Please sign in to comment.