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

Harden validator for partially implemented APIs #1181

Merged
merged 4 commits into from May 21, 2022
Merged

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented May 21, 2022

Closes #1180 by hardening some of the validator testing, namely:

  1. Prevent skipping response_field tests if page_limit has no effect
  2. Use a weirder default value for page_limit (4 instead of 5) so that tests cannot accidentally pass.
  3. Do not rely on page_offset being implemented when choosing the archetypal entry for filtering
  4. Prevent optional filter tests from ending tests early when non-optional sections should fail
  5. Assume that inclusive tests contain the archetypal result on the first page (i.e. do not allow sorting to change between queries). This was allowing completely missing filtering to pass all tests, as the results may have been on future pages

- Remove CLI control of page_limit and set the default value to
something less common (4)
- Check `next` links for duplicates during pagination
- Make sure optional queries don't do an 'allowed failure'
before more important non-optional checks
- Assume that the archetypal entry will always be on the first
page of results (assumes constant default sorting from the API)
rather than allowing bad results to hide in future pages
@ml-evs ml-evs added priority/high Issue or PR with a consensus of high priority validator Related to the OPTIMADE validator labels May 21, 2022
@ml-evs
Copy link
Member Author

ml-evs commented May 21, 2022

I think this is fairly major, if tests pass I will self-merge my changes and release so that the dashboard is up to date before the workshop.

@@ -825,8 +823,48 @@ def _construct_single_property_filters(
else:
num_data_returned[operator] = response["meta"].get("data_returned")

if prop in CONF.unique_properties and operator == "=":
Copy link
Member Author

@ml-evs ml-evs May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block was just moved up from below the reversed query tests, with this line being the only change (previously it assumed "=" was already in the dict).

@codecov
Copy link

codecov bot commented May 21, 2022

Codecov Report

Merging #1181 (cdabed9) into master (96a46b3) will decrease coverage by 0.01%.
The diff coverage is 73.91%.

@@            Coverage Diff             @@
##           master    #1181      +/-   ##
==========================================
- Coverage   92.42%   92.40%   -0.02%     
==========================================
  Files          68       68              
  Lines        3909     3912       +3     
==========================================
+ Hits         3613     3615       +2     
- Misses        296      297       +1     
Flag Coverage Δ
project 92.40% <73.91%> (-0.02%) ⬇️
validator 92.40% <73.91%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
optimade/validator/validator.py 83.91% <72.72%> (-0.13%) ⬇️
optimade/validator/__init__.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 96a46b3...cdabed9. Read the comment docs.

response, message = self._get_endpoint(
f"{endp}?page_offset={random.randint(0, data_returned-1)}&response_fields={','.join(properties)}",
multistage=True,
archetypal_entry = response.json()["data"][
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes the need for page_offset to be implemented by the API, and instead just chooses a random result from the first page of the API results to use for the filter tests.

@@ -557,7 +555,7 @@ def _check_response_fields(self, endp: str, fields: List[str]) -> Tuple[bool, st
test_query = f"{endp}?response_fields={','.join(subset_fields)}&page_limit=1"
response, _ = self._get_endpoint(test_query, multistage=True)

if response and len(response.json()["data"]) == 1:
if response and len(response.json()["data"]) >= 0:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously allowing databases that did not support page_limit to skip this test

Comment on lines +1293 to +1298
if next_link in previous_links:
raise ResponseError(
f"The next link {next_link} has been provided already for a previous page."
)
previous_links.add(next_link)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, it was valid to return the same next link for every page and get stuck in a cycle

@ml-evs
Copy link
Member Author

ml-evs commented May 21, 2022

Just added some comments summarizing the changes in this PR, for posterity.

@ml-evs ml-evs merged commit e940a20 into master May 21, 2022
@ml-evs ml-evs deleted the ml-evs/harden_validator branch May 21, 2022 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/high Issue or PR with a consensus of high priority validator Related to the OPTIMADE validator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server validation incorrectly passes with various unimplemented features
1 participant