-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
case search "date_add" function #31388
Conversation
corehq/apps/case_search/dsl_utils.py
Outdated
@@ -12,6 +12,8 @@ | |||
def unwrap_value(domain, node): | |||
"""Returns the value of the node if it is wrapped in a function, otherwise just returns the node | |||
""" | |||
if isinstance(node, (str, int, float, bool)): | |||
return node |
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.
Curious what this achieves that the if not isinstance(node, FunctionCall)
line doesn't catch?
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.
Good point. What I was wanting to do was only permit certain types here. For example it should not return a BinaryExpression
. But on more reflection perhaps that doesn't belong here.
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.
assert node.name == 'date_add' | ||
if len(node.args) != 3: | ||
raise XPathFunctionException( | ||
_("The \"date_add\" function expects three arguments"), |
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.
nit: maybe add which arguments it needs?
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.
_("The \"date_add\" function expects three arguments"), | |
_("The \"date_add\" function expects three arguments, got {count}".format( | |
count=len(node.args), | |
)), |
try: | ||
result = date + relativedelta(**{interval_type: quantity}) | ||
except ValueError as e: | ||
raise XPathFunctionException(str(e), serialize(node)) |
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.
nit: I think this will show a python style error to the user which might be hard to understand. Is there another way we could show this error to the user?
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've handled the value error but kept the try block for unexpected exceptions: 3c448f5
assert node.name == 'date_add' | ||
if len(node.args) != 3: | ||
raise XPathFunctionException( | ||
_("The \"date_add\" function expects three arguments"), |
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.
_("The \"date_add\" function expects three arguments"), | |
_("The \"date_add\" function expects three arguments, got {count}".format( | |
count=len(node.args), | |
)), |
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.
Thanks for fixing the formatting error on my got {count}
suggestion.
CEP: #31325
Product Description
Adds a 'date_add' function to the case search query language to support calculating relative dates:
Technical Summary
Implements the
date_add
function as outlined in the CEP. See test cases for usage.Best reviewed by commit.
Feature Flag
Case Search, CLE
Safety Assurance
Safety story
New case search function should not have any impact until it is used in a query. The code for the function and case search queries in general is well tested.
Automated test coverage
Added tests for the specific function.
QA Plan
None
Rollback instructions
Labels & Review