You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by er...@apache.org on 2020/05/27 16:02:24 UTC

[incubator-superset] branch master updated: fix: annotation layer json (#9915)

This is an automated email from the ASF dual-hosted git repository.

erikrit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new c4040a2  fix: annotation layer json (#9915)
c4040a2 is described below

commit c4040a2ae0b2fec5550419265ca542f58757db74
Author: Erik Ritter <er...@airbnb.com>
AuthorDate: Wed May 27 09:02:03 2020 -0700

    fix: annotation layer json (#9915)
    
    * fix: annotation layer json
    
    * attempt to add a test
    
    * [tests] Fixing test
    
    Co-authored-by: John Bodley <jo...@airbnb.com>
---
 superset/views/core.py        | 15 +++++++++++++++
 tests/core_tests.py           | 25 +++++++++++++++++++++++++
 tests/superset_test_config.py |  2 ++
 3 files changed, 42 insertions(+)

diff --git a/superset/views/core.py b/superset/views/core.py
index 1027868..716c11a 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -685,6 +685,21 @@ class Superset(BaseSupersetView):
         form_data = get_form_data()[0]
         form_data["layer_id"] = layer_id
         form_data["filters"] = [{"col": "layer_id", "op": "==", "val": layer_id}]
+        # Set all_columns to ensure the TableViz returns the necessary columns to the
+        # frontend.
+        form_data["all_columns"] = [
+            "created_on",
+            "changed_on",
+            "id",
+            "start_dttm",
+            "end_dttm",
+            "layer_id",
+            "short_descr",
+            "long_descr",
+            "json_metadata",
+            "created_by_fk",
+            "changed_by_fk",
+        ]
         datasource = AnnotationDatasource()
         viz_obj = viz.viz_types["table"](datasource, form_data=form_data, force=False)
         payload = viz_obj.get_payload()
diff --git a/tests/core_tests.py b/tests/core_tests.py
index 12293c1..aea4f5d 100644
--- a/tests/core_tests.py
+++ b/tests/core_tests.py
@@ -25,6 +25,7 @@ import json
 import logging
 import os
 from typing import Dict, List, Optional
+from urllib.parse import quote
 
 import pytz
 import random
@@ -50,6 +51,7 @@ from superset.datasets.dao import DatasetDAO
 from superset.db_engine_specs.base import BaseEngineSpec
 from superset.db_engine_specs.mssql import MssqlEngineSpec
 from superset.models import core as models
+from superset.models.annotations import Annotation, AnnotationLayer
 from superset.models.dashboard import Dashboard
 from superset.models.datasource_access_request import DatasourceAccessRequest
 from superset.models.slice import Slice
@@ -177,6 +179,29 @@ class CoreTests(SupersetTestCase):
         resp = self.get_resp(slc.explore_json_url)
         assert '"Jennifer"' in resp
 
+    def test_annotation_json_endpoint(self):
+        # Set up an annotation layer and annotation
+        layer = AnnotationLayer(name="foo", descr="bar")
+        db.session.add(layer)
+        db.session.commit()
+
+        annotation = Annotation(
+            layer_id=layer.id,
+            short_descr="my_annotation",
+            start_dttm=datetime.datetime(2020, 5, 20, 18, 21, 51),
+            end_dttm=datetime.datetime(2020, 5, 20, 18, 31, 51),
+        )
+
+        db.session.add(annotation)
+        db.session.commit()
+
+        resp = self.get_resp(
+            f"/superset/annotation_json/{layer.id}?form_data="
+            + quote(json.dumps({"time_range": "100 years ago : now"}))
+        )
+
+        assert "my_annotation" in resp
+
     def test_old_slice_csv_endpoint(self):
         self.login(username="admin")
         slc = self.get_slice("Girls", db.session)
diff --git a/tests/superset_test_config.py b/tests/superset_test_config.py
index a3def4a..3ce6745 100644
--- a/tests/superset_test_config.py
+++ b/tests/superset_test_config.py
@@ -76,3 +76,5 @@ CELERY_CONFIG = CeleryConfig
 CUSTOM_TEMPLATE_PROCESSORS = {
     CustomPrestoTemplateProcessor.engine: CustomPrestoTemplateProcessor
 }
+
+PRESERVE_CONTEXT_ON_EXCEPTION = False