-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
chore: Remove obsolete legacy visualizations #24694
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,10 @@ | |
from superset.common.query_actions import get_query_results | ||
from superset.common.utils import dataframe_utils | ||
from superset.common.utils.query_cache_manager import QueryCacheManager | ||
from superset.common.utils.time_range_utils import get_since_until_from_query_object | ||
from superset.common.utils.time_range_utils import ( | ||
get_since_until_from_query_object, | ||
get_since_until_from_time_range, | ||
) | ||
from superset.connectors.base.models import BaseDatasource | ||
from superset.constants import CacheRegion, TimeGrain | ||
from superset.daos.annotation import AnnotationLayerDAO | ||
|
@@ -64,6 +67,7 @@ | |
from superset.utils.date_parser import get_past_or_future, normalize_time_delta | ||
from superset.utils.pandas_postprocessing.utils import unescape_separator | ||
from superset.views.utils import get_viz | ||
from superset.viz import viz_types | ||
|
||
if TYPE_CHECKING: | ||
from superset.common.query_context import QueryContext | ||
|
@@ -685,22 +689,53 @@ def get_native_annotation_data(query_obj: QueryObject) -> dict[str, Any]: | |
def get_viz_annotation_data( | ||
annotation_layer: dict[str, Any], force: bool | ||
) -> dict[str, Any]: | ||
chart = ChartDAO.find_by_id(annotation_layer["value"]) | ||
if not chart: | ||
# pylint: disable=import-outside-toplevel,superfluous-parens | ||
from superset.charts.data.commands.get_data_command import ChartDataCommand | ||
|
||
if not (chart := ChartDAO.find_by_id(annotation_layer["value"])): | ||
raise QueryObjectValidationError(_("The chart does not exist")) | ||
if not chart.datasource: | ||
raise QueryObjectValidationError(_("The chart datasource does not exist")) | ||
form_data = chart.form_data.copy() | ||
form_data.update(annotation_layer.get("overrides", {})) | ||
|
||
try: | ||
viz_obj = get_viz( | ||
datasource_type=chart.datasource.type, | ||
datasource_id=chart.datasource.id, | ||
form_data=form_data, | ||
force=force, | ||
) | ||
payload = viz_obj.get_payload() | ||
return payload["data"] | ||
if chart.viz_type in viz_types: | ||
if not chart.datasource: | ||
raise QueryObjectValidationError( | ||
_("The chart datasource does not exist"), | ||
) | ||
|
||
form_data = chart.form_data.copy() | ||
form_data.update(annotation_layer.get("overrides", {})) | ||
|
||
payload = get_viz( | ||
datasource_type=chart.datasource.type, | ||
datasource_id=chart.datasource.id, | ||
form_data=form_data, | ||
force=force, | ||
).get_payload() | ||
|
||
return payload["data"] | ||
|
||
if not (query_context := chart.get_query_context()): | ||
raise QueryObjectValidationError( | ||
_("The chart query context does not exist"), | ||
) | ||
|
||
if overrides := annotation_layer.get("overrides"): | ||
if time_grain_sqla := overrides.get("time_grain_sqla"): | ||
for query_object in query_context.queries: | ||
query_object.extras["time_grain_sqla"] = time_grain_sqla | ||
|
||
if time_range := overrides.get("time_range"): | ||
from_dttm, to_dttm = get_since_until_from_time_range(time_range) | ||
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. The |
||
|
||
for query_object in query_context.queries: | ||
query_object.from_dttm = from_dttm | ||
query_object.to_dttm = to_dttm | ||
|
||
query_context.force = force | ||
command = ChartDataCommand(query_context) | ||
command.validate() | ||
payload = command.run() | ||
return {"records": payload["queries"][0]["data"]} | ||
except SupersetException as ex: | ||
raise QueryObjectValidationError(error_msg_from_exception(ex)) from ex | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,6 +424,16 @@ def create_slices(tbl: SqlaTable) -> tuple[list[Slice], list[Slice]]: | |
viz_type="table", | ||
metrics=metrics, | ||
), | ||
query_context=get_slice_json( | ||
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. @michael-s-molina even though you were able to run the Celery tests locally without issue, after a few tweaks (increasing timeouts to address the performance degradation on M1 silica) I was able to see the following error: ![]() I don't fully grok where/when the query context is persisted (the only place I could see where the query context was generated from the payload/form-data was via the /api/chart/v1//data/ RESTful API GET endpoint), but it does seem the existence of query context seemed somewhat sporadic. Maybe @villebro can provide more insights in terms of how/where this is generated/persisted as in the example data currently only the "Pivot Table v2" chart (per the The TL;DR is similar to the "Pivot Table v2" chart when I explicitly added the query context for the "Daily Totals" chart (which backs the annotation layer in the Cypress test which was failing) the test passed. |
||
default_query_context, | ||
queries=[ | ||
{ | ||
"columns": ["ds"], | ||
"metrics": metrics, | ||
"time_range": "1983 : 2023", | ||
} | ||
], | ||
), | ||
), | ||
Slice( | ||
**slice_kwargs, | ||
|
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.
Same logic was previously but indented.