-
-
Notifications
You must be signed in to change notification settings - Fork 85
[14.0][IMP] endpoint: support usage of querystring parameters #80
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
base: 14.0
Are you sure you want to change the base?
Conversation
Hi @simahawk, |
Review is appreciated but please don't merge yet, there might be a few changes. |
d1bff46
to
3532d63
Compare
Ready for review. |
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.
Thank you! Something I was thinking about since a while ;)
Just 1 remark about the naming: I prefer to make explicit everywhere down the stack, as params
is quite an abused term 😉
Also, would be nice to see a test.
@@ -76,8 +76,10 @@ def _default_code_snippet_docs(self): | |||
* Response | |||
* werkzeug | |||
* exceptions | |||
* params |
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.
* params | |
* querystring_params |
@@ -134,10 +136,11 @@ def _code_snippet_log_func(self, message, level="info"): | |||
), | |||
) | |||
|
|||
def _handle_exec__code(self, request): | |||
def _handle_exec__code(self, request, params=None): |
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.
def _handle_exec__code(self, request, params=None): | |
def _handle_exec__code(self, request, querystring_params=None): |
@@ -17,7 +17,7 @@ def _handle_endpoint(self, env, model, endpoint_route, **params): | |||
if not endpoint: | |||
raise NotFound() | |||
endpoint._validate_request(request) | |||
result = endpoint._handle_request(request) | |||
result = endpoint._handle_request(request, params=params) |
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.
result = endpoint._handle_request(request, params=params) | |
result = endpoint._handle_request(request, querystring_params=params) |
if not self._code_snippet_valued(): | ||
return {} | ||
eval_ctx = self._get_code_snippet_eval_context(request) | ||
eval_ctx["params"] = params or {} |
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.
eval_ctx["params"] = params or {} | |
eval_ctx["querystring_params"] = querystring_params or {} |
@@ -184,14 +187,18 @@ def _get_handler(self): | |||
_("Missing handler for exec mode %s") % self.exec_mode | |||
) | |||
|
|||
def _handle_request(self, request): | |||
def _handle_request(self, request, params=None): |
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.
def _handle_request(self, request, params=None): | |
def _handle_request(self, request, querystring_params=None): |
# Switch user for the whole process | ||
self_with_user = self | ||
if self.exec_as_user_id: | ||
self_with_user = self.with_user(user=self.exec_as_user_id) | ||
handler = self_with_user._get_handler() | ||
try: | ||
res = handler(request) | ||
# In case the handler does not support params |
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 doubt we have any other handler ATM but just in case... ok, let's keep this but I would add a separated commit for backward compat that we can easily drop on migration.
Something like:
[imp] endpoint: support querystring params
[imp] endpoint: backward compat for querystring params
Old handlers might not accept this new kw args
Trash this commit in future versions. Eg: v18.
if params: | ||
res = handler(request, params=params) |
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.
if params: | |
res = handler(request, params=params) | |
if querystring_params: | |
res = handler(request, querystring_params=querystring_params) |
3532d63
to
f002179
Compare
No description provided.