-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
[fix] Ensuring cache warmup respects request form data #9665
Merged
john-bodley
merged 1 commit into
apache:master
from
john-bodley:john-bodley--issue-9664
Apr 29, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
from urllib import parse | ||
|
||
import simplejson as json | ||
from flask import request | ||
from flask import g, request | ||
|
||
import superset.models.core as models | ||
from superset import app, db, is_feature_enabled | ||
|
@@ -99,23 +99,28 @@ def get_viz( | |
return viz_obj | ||
|
||
|
||
def get_form_data(slice_id=None, use_slice_data=False): | ||
def get_form_data( | ||
slice_id: Optional[int] = None, use_slice_data: bool = False | ||
) -> Tuple[Dict[str, Any], Optional[Slice]]: | ||
form_data = {} | ||
post_data = request.form.get("form_data") | ||
request_form_data = request.form.get("form_data") | ||
request_args_data = request.args.get("form_data") | ||
# Supporting POST | ||
if post_data: | ||
form_data.update(json.loads(post_data)) | ||
# request params can overwrite post body | ||
if request_form_data: | ||
form_data.update(json.loads(request_form_data)) | ||
# request params can overwrite the body | ||
if request_args_data: | ||
form_data.update(json.loads(request_args_data)) | ||
|
||
# Fallback to using the Flask globals (used for cache warmup) if defined. | ||
if not form_data and hasattr(g, "form_data"): | ||
form_data = getattr(g, "form_data") | ||
|
||
url_id = request.args.get("r") | ||
if url_id: | ||
saved_url = db.session.query(models.Url).filter_by(id=url_id).first() | ||
if saved_url: | ||
url_str = parse.unquote_plus( | ||
saved_url.url.split("?")[1][10:], encoding="utf-8", errors=None | ||
saved_url.url.split("?")[1][10:], encoding="utf-8" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
) | ||
url_form_data = json.loads(url_str) | ||
# allow form_date in request override saved url | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@villebro I was spinning my wheels for quite some time trying to get
test_request_context()
to work and then realize that this isn't explicitly related to the POST method and not is the body of the request a JSON object, i.e., theform_data
field is actually further encoded as a JSON object.The form-data is messy and we probably should strive to standardize this at some stage. For now I've renamed
post_data
asrequest_form_data
which is more accurate.