Skip to content

[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

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from

Conversation

dreispt
Copy link
Member

@dreispt dreispt commented Dec 23, 2024

No description provided.

@OCA-git-bot
Copy link
Contributor

Hi @simahawk,
some modules you are maintaining are being modified, check this out!

@dreispt dreispt requested a review from simahawk December 23, 2024 11:49
@dreispt dreispt changed the title [IMP] endpoint: support usage of querystring parameters [14.0][IMP] endpoint: support usage of querystring parameters Dec 23, 2024
@dreispt
Copy link
Member Author

dreispt commented Dec 27, 2024

Review is appreciated but please don't merge yet, there might be a few changes.

@dreispt dreispt marked this pull request as draft December 27, 2024 13:17
@dreispt dreispt force-pushed the 14-dr-endpoint-params branch from d1bff46 to 3532d63 Compare January 2, 2025 12:29
@dreispt dreispt marked this pull request as ready for review January 3, 2025 10:18
@dreispt
Copy link
Member Author

dreispt commented Jan 3, 2025

Ready for review.

Copy link
Contributor

@simahawk simahawk left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* 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):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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 {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Contributor

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.

Comment on lines +198 to +199
if params:
res = handler(request, params=params)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if params:
res = handler(request, params=params)
if querystring_params:
res = handler(request, querystring_params=querystring_params)

@dreispt dreispt force-pushed the 14-dr-endpoint-params branch from 3532d63 to f002179 Compare March 16, 2025 19:20
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.

3 participants