-
Notifications
You must be signed in to change notification settings - Fork 6
Review structure of Query.conditions #92
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
Review structure of Query.conditions #92
Conversation
even if there is only one single condition for an attribute.
the keys, but rather set the values to a template string including the JPQL function when present.
c5f5b18 to
88abf6e
Compare
OrderedDict having template strings as values.
|
I now also added JPQL function support for |
tutorial example
MRichards99
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm generally happy with this, but could you update the docstring for addConditions as per my comment please?
| :param conditions: the conditions to restrict the search | ||
| result. This must be a mapping of attribute names to | ||
| conditions on that attribute. The latter may either be a | ||
| string with a single condition or a list of strings to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please could you change this documentation to remove the section which states that the key could be a string or list of strings? Due to the list comprehension introduced on line 444, the condition key will always be a list, even if it only contains a single string. For example, query.addConditions({"id": "> '5'"}).
I noticed this when running the tests on DataGateway API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I beg to differ. As for any other method, the docstring of addConditions() documents the arguments that the method accepts. It does not document the internal data structures in the attributes of a Query object. These are intentionally left undocumented and thus whetever happens in line 444 is not relevant here. The conditions argument to addConditions() must be a mapping of attribute names to conditions, where the conditions in turn may either be simple strings or list of strings. So this docstring is correct. Your example query.addConditions({"id": "> '5'"}) in fact demonstrates that a simple string value will be accepted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is something which I didn't initially consider when reading the docstring. I think I was slightly surprised that all keys in self.conditions will always be a list of strings, although I don't think this is a problem. I fixed the tests on DataGateway API and everything behaves as I expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, we will need to mention in the changelog that the internal data structures in the Query class have changed. This also has an impact on the formal string representation operator __repr__(). I'm going to open another issue on the latter, even if only for the sake of documentaion.
This amends #89:
Query.conditionsbut rather set the value to a template string including the JPQL function when present,Query.conditionsalways as a list, even if there is only one single condition,This addresses the first two bullets in my review of #89 and as a side effect also fixes the error case mentioned in the review. I still might add a few more changes, in particular implementing support for JPQL functions also in
order, hence the draft status.