-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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(query-object): extra time-range-endpoints #13331
fix(query-object): extra time-range-endpoints #13331
Conversation
bea95d2
to
a2b26ac
Compare
I don't really get why is |
There are recent updates to both both Time Picker module and the table chart (which migrated to the new API v1 endpoint) so a lot of things could go wrong in this process... |
if config["SIP_15_ENABLED"] and "time_range_endpoints" not in self.extras: | ||
self.extras["time_range_endpoints"] = get_time_range_endpoints(form_data={}) | ||
if config["SIP_15_ENABLED"]: | ||
self.extras["time_range_endpoints"] = get_time_range_endpoints( | ||
form_data=self.extras | ||
) |
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.
Oh wow, that would explain some of the problems people have been having with time range endpoints not working correctly. Passing self.extras
as form_data
feels slightly wrong; should we change the sig so that it's def get_time_range_endpoints(extras: ExtraFormData)
or similar and perhaps add a TypedDict
for it in superset/utils/core.py
like here?
superset/superset/utils/core.py
Lines 175 to 177 in 8ab45c9
class DatasourceDict(TypedDict): | |
type: str | |
id: int |
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 the issue is that under other scenarios the full form data is required. We could have slots for both form_data
and extras
but I think that adds more confusion.
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 think there is a test case:
superset/tests/query_context_tests.py
Lines 170 to 185 in 0a00153
def test_query_context_time_range_endpoints(self): | |
""" | |
Ensure that time_range_endpoints are populated automatically when missing | |
from the payload. | |
""" | |
self.login(username="admin") | |
payload = get_query_context("birth_names") | |
del payload["queries"][0]["extras"]["time_range_endpoints"] | |
query_context = ChartDataQueryContextSchema().load(payload) | |
query_object = query_context.queries[0] | |
extras = query_object.to_dict()["extras"] | |
assert "time_range_endpoints" in extras | |
self.assertEqual( | |
extras["time_range_endpoints"], | |
(TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE), | |
) |
that captures the intention of the original code.
Do you mind adding a test case so your change is also tested?
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.
@ktmud this change captures the sentiment of the test, i.e., ensuring that the in extras
the data is encoded as an enum rather than string, unless I'm confused regarding the ChartDataQueryContextSchema
behavior.
@ktmud it's been a while since I wrote this code, but I believe the |
Codecov Report
@@ Coverage Diff @@
## master #13331 +/- ##
==========================================
+ Coverage 77.19% 80.42% +3.22%
==========================================
Files 872 300 -572
Lines 45101 24420 -20681
Branches 5435 0 -5435
==========================================
- Hits 34817 19639 -15178
+ Misses 10161 4781 -5380
+ Partials 123 0 -123
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
a2b26ac
to
3d7bc08
Compare
4c7455b
to
8d5697b
Compare
8d5697b
to
35bf533
Compare
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.
LGTM
if config["SIP_15_ENABLED"] and "time_range_endpoints" not in self.extras: | ||
self.extras["time_range_endpoints"] = get_time_range_endpoints(form_data={}) | ||
if config["SIP_15_ENABLED"]: | ||
self.extras["time_range_endpoints"] = get_time_range_endpoints( | ||
form_data=self.extras | ||
) |
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 think there is a test case:
superset/tests/query_context_tests.py
Lines 170 to 185 in 0a00153
def test_query_context_time_range_endpoints(self): | |
""" | |
Ensure that time_range_endpoints are populated automatically when missing | |
from the payload. | |
""" | |
self.login(username="admin") | |
payload = get_query_context("birth_names") | |
del payload["queries"][0]["extras"]["time_range_endpoints"] | |
query_context = ChartDataQueryContextSchema().load(payload) | |
query_object = query_context.queries[0] | |
extras = query_object.to_dict()["extras"] | |
assert "time_range_endpoints" in extras | |
self.assertEqual( | |
extras["time_range_endpoints"], | |
(TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE), | |
) |
that captures the intention of the original code.
Do you mind adding a test case so your change is also tested?
Co-authored-by: John Bodley <john.bodley@airbnb.com>
SUMMARY
I'm really perplexed why this issue has recently surfaced and/or been reported and why it only applies to certain visualization types (is there any chance this is overridden by various chart types), but it seems like the Python date format wasn't being adhered to due to poorly formed extra time-range-endpoints.
More specifically for the QueryObject the
extra
fields are coming fromsuperset-ui
where, if defined, thetime_range_endpoints
is a tuple of strings which are never converted to a tuple ofTimeRangeEndpoint
enums and thus this check is false meaning the default date format is never adhered to.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TEST PLAN
CI.
ADDITIONAL INFORMATION