Skip to content

Ensure that DJORNL queries do not have additional properties#26

Merged
jayrbolton merged 3 commits intodevelopfrom
remove_ws_ids
Sep 1, 2020
Merged

Ensure that DJORNL queries do not have additional properties#26
jayrbolton merged 3 commits intodevelopfrom
remove_ws_ids

Conversation

@ialarmedalien
Copy link
Copy Markdown
Collaborator

Disallow any additional parameters in the DJORNL queries.

  • Remove injected ws_ids param unless it is required by the query
  • Add "additionalProperties" to DJORNL stored queries and add tests
  • Add generic distance.yaml file for queries with a distance param

Closes #11

  • I updated the README.md docs to reflect this change. -- N/A
  • This is not a breaking API change

Add "additionalProperties" to stored queries
Comment on lines +102 to +107
has_ws_ids = False
if 'ws_ids' in stored_query['query']:
json_body['ws_ids'] = ws_ids
has_ws_ids = True
else:
del json_body['ws_ids']
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If the stored query doesn't have ws_ids in it, the additional ws_ids param will not be needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As I mentioned in this issue, I think a simpler way to achieve the same thing with less code is to just remove line 75 here: https://github.com/kbase/relation_engine/blob/develop/relation_engine_server/api_versions/api_v1.py#L75

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If the query doesn't use ws_ids, it is just potentially slowing things down by retrieving the list of IDs and adding them to the query. The cleanest solution would be to check whether the query/stored query mentions ws_ids, and only if it does, fetch the IDs from the workspace to add to the request object and alter the AQL to include the LET ws_ids = @ws_ids line.

I've reverted things to how they were, with the ws_ids injection, but moved the setting of ws_ids to after JSON validation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Avoiding an extra workspace request when the query does not use ws_ids is a good point, I agree that would be a good additional benefit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm seeing the current version of the code doesn't try to avoid the workspace request, and also doesn't remove line 75. Maybe you haven't pushed yet?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OK, I have edited it to only add ws_ids and pull the list from the workspace when ws_ids is mentioned in the query.

Comment on lines +115 to +116
stored_query_path = spec_loader.get_stored_query(query_name, path_only=True)
run_validator(schema_file=stored_query_path, data=json_body, validate_at='/params')
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Use the path, so that relative references in the files work.

@jayrbolton
Copy link
Copy Markdown
Contributor

Done reviewing, one comment above

# fetch number of documents to return
batch_size = int(flask.request.args.get('batch_size', 10000))
full_count = flask.request.args.get('full_count', False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You don't have to revert, but i prefer not having all these additional newlines in the function body

Copy link
Copy Markdown
Collaborator Author

@ialarmedalien ialarmedalien Sep 1, 2020

Choose a reason for hiding this comment

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

I find adding newlines aids readability -- otherwise it's just a bunch of lines with the same indentation and there's added cognitive load in understanding the code before you can edit it. 😖

@jayrbolton jayrbolton merged commit 0d63bbf into develop Sep 1, 2020
@jayrbolton jayrbolton deleted the remove_ws_ids branch September 1, 2020 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow use of additionalProperties in stored query schemas

2 participants