You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "diegomedina248 (via GitHub)" <gi...@apache.org> on 2023/02/02 13:58:39 UTC

[GitHub] [superset] diegomedina248 opened a new pull request, #22964: chore: Migrate /superset/user_slices and /superset/fave_slices to API v1

diegomedina248 opened a new pull request, #22964:
URL: https://github.com/apache/superset/pull/22964

   ### SUMMARY
   Continuing the effort on deprecating all /superset/ REST API endpoints
   Deprecates `/superset/user_slices` for `/api/v1/chart/user_slices/`
   Deprecates `/superset/fave_slices` for `/api/v1/chart/user_slices/`
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] hughhhh merged pull request #22964: chore: Migrate /superset/user_slices and /superset/fave_slices to API v1

Posted by "hughhhh (via GitHub)" <gi...@apache.org>.
hughhhh merged PR #22964:
URL: https://github.com/apache/superset/pull/22964


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] john-bodley commented on a diff in pull request #22964: chore: Migrate /superset/user_slices and /superset/fave_slices to API v1

Posted by "john-bodley (via GitHub)" <gi...@apache.org>.
john-bodley commented on code in PR #22964:
URL: https://github.com/apache/superset/pull/22964#discussion_r1096083263


##########
superset/charts/commands/get_slices.py:
##########
@@ -0,0 +1,67 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import logging
+from typing import cast, Optional
+
+from flask_appbuilder.models.sqla import Model
+
+from superset import security_manager
+from superset.charts.dao import ChartDAO
+from superset.commands.base import BaseCommand
+from superset.utils.core import get_user_id
+from superset.utils.dates import datetime_to_epoch
+
+logger = logging.getLogger(__name__)
+
+
+class GetUserSlicesCommand(BaseCommand):
+    _user_id: Optional[int]
+
+    def __init__(self, user_id: Optional[int] = None):
+        self._user_id = user_id
+
+    def run(self) -> Model:
+        self.validate()
+
+        slices = ChartDAO.user_slices(cast(int, self._user_id))
+
+        payload = []
+        for o in slices:

Review Comment:
   We have a tendency to use `slc` rather than the more opaque `o` to represent a slice. That said I’m not sure what `o` actually represents given that is presented as `o.Slice`.



##########
superset/charts/commands/get_slices.py:
##########
@@ -0,0 +1,67 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import logging
+from typing import cast, Optional
+
+from flask_appbuilder.models.sqla import Model
+
+from superset import security_manager
+from superset.charts.dao import ChartDAO
+from superset.commands.base import BaseCommand
+from superset.utils.core import get_user_id
+from superset.utils.dates import datetime_to_epoch
+
+logger = logging.getLogger(__name__)
+
+
+class GetUserSlicesCommand(BaseCommand):
+    _user_id: Optional[int]
+
+    def __init__(self, user_id: Optional[int] = None):
+        self._user_id = user_id
+
+    def run(self) -> Model:
+        self.validate()
+
+        slices = ChartDAO.user_slices(cast(int, self._user_id))
+
+        payload = []
+        for o in slices:
+            item = {
+                "id": o.Slice.id,
+                "title": o.Slice.slice_name,
+                "url": o.Slice.slice_url,
+                "data": o.Slice.form_data,
+                "dttm": datetime_to_epoch(
+                    o.FavStar.dttm if o.FavStar else o.Slice.changed_on
+                ),
+                "viz_type": o.Slice.viz_type,
+                "is_favorite": bool(o.FavStar),
+            }
+            if o.Slice.created_by:
+                user = o.Slice.created_by
+                item["creator"] = str(user)
+                item["creator_url"] = "/superset/profile/{}/".format(user.username)
+            payload.append(item)
+
+        return payload
+
+    def validate(self) -> None:
+        if not self._user_id:

Review Comment:
   I know we do this elsewhere but mutating state inside `validate` seems wrong to me.



##########
superset/charts/dao.py:
##########
@@ -82,3 +84,34 @@ def favorited_ids(charts: List[Slice]) -> List[FavStar]:
             )
             .all()
         ]
+
+    @staticmethod
+    def user_slices(user_id: int) -> List[Any]:
+        owner_ids_query = (
+            db.session.query(Slice.id)
+            .join(Slice.owners)
+            .filter(security_manager.user_model.id == user_id)
+        )
+
+        return (
+            db.session.query(Slice, FavStar)
+            .join(
+                FavStar,
+                and_(
+                    FavStar.user_id == user_id,
+                    FavStar.class_name == "slice",
+                    Slice.id == FavStar.obj_id,
+                ),
+                isouter=True,
+            )
+            .filter(  # pylint: disable=comparison-with-callable
+                or_(
+                    Slice.id.in_(owner_ids_query),

Review Comment:
   Any reason this isn’t a join as opposed to a subquery? I suspect the subquery likely fetches significantly more slices than the user favorited.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] codecov[bot] commented on pull request #22964: chore: Migrate /superset/user_slices and /superset/fave_slices to API v1

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #22964:
URL: https://github.com/apache/superset/pull/22964#issuecomment-1413795931

   # [Codecov](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#22964](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (67b9b31) into [master](https://codecov.io/gh/apache/superset/commit/ed7b3533bcc119b2240a613ebc56ace33f1e1002?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (ed7b353) will **decrease** coverage by `10.44%`.
   > The diff coverage is `70.31%`.
   
   ```diff
   @@             Coverage Diff             @@
   ##           master   #22964       +/-   ##
   ===========================================
   - Coverage   66.63%   56.19%   -10.44%     
   ===========================================
     Files        1876     1877        +1     
     Lines       72084    72143       +59     
     Branches     7857     7857               
   ===========================================
   - Hits        48031    40543     -7488     
   - Misses      22039    29586     +7547     
     Partials     2014     2014               
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | hive | `?` | |
   | presto | `52.65% <66.66%> (+0.02%)` | :arrow_up: |
   | python | `58.81% <70.00%> (-21.69%)` | :arrow_down: |
   | sqlite | `?` | |
   | unit | `52.45% <70.00%> (+0.02%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [superset/constants.py](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvY29uc3RhbnRzLnB5) | `100.00% <ø> (ø)` | |
   | [superset/charts/commands/get\_slices.py](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvY2hhcnRzL2NvbW1hbmRzL2dldF9zbGljZXMucHk=) | `48.27% <48.27%> (ø)` | |
   | [...rset-frontend/src/profile/components/Favorites.tsx](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL3Byb2ZpbGUvY29tcG9uZW50cy9GYXZvcml0ZXMudHN4) | `77.77% <66.66%> (ø)` | |
   | [superset/charts/api.py](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvY2hhcnRzL2FwaS5weQ==) | `51.07% <70.00%> (-35.12%)` | :arrow_down: |
   | [...ontrols/AnnotationLayerControl/AnnotationLayer.jsx](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2V4cGxvcmUvY29tcG9uZW50cy9jb250cm9scy9Bbm5vdGF0aW9uTGF5ZXJDb250cm9sL0Fubm90YXRpb25MYXllci5qc3g=) | `74.40% <100.00%> (ø)` | |
   | [superset/charts/dao.py](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvY2hhcnRzL2Rhby5weQ==) | `56.00% <100.00%> (-34.91%)` | :arrow_down: |
   | [superset/charts/schemas.py](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvY2hhcnRzL3NjaGVtYXMucHk=) | `99.37% <100.00%> (+0.02%)` | :arrow_up: |
   | [superset/views/core.py](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvdmlld3MvY29yZS5weQ==) | `36.13% <100.00%> (-38.29%)` | :arrow_down: |
   | [superset/utils/dashboard\_import\_export.py](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvdXRpbHMvZGFzaGJvYXJkX2ltcG9ydF9leHBvcnQucHk=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [superset/tags/core.py](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvdGFncy9jb3JlLnB5) | `4.54% <0.00%> (-95.46%)` | :arrow_down: |
   | ... and [278 more](https://codecov.io/gh/apache/superset/pull/22964?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] dpgaspar commented on a diff in pull request #22964: chore: Migrate /superset/user_slices and /superset/fave_slices to API v1

Posted by "dpgaspar (via GitHub)" <gi...@apache.org>.
dpgaspar commented on code in PR #22964:
URL: https://github.com/apache/superset/pull/22964#discussion_r1098969958


##########
superset/charts/api.py:
##########
@@ -914,3 +916,43 @@ def import_(self) -> Response:
         )
         command.run()
         return self.response(200, message="OK")
+
+    @expose("/user_slices/")
+    @expose("/user_slices/<int:user_id>/")

Review Comment:
   could we just use `api/v1/chart/?q=(filters:!((col:owners,opr:rel_m_m,value:<USER_ID>)),order_direction:desc,page:0,page_size:25)`
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] diegomedina248 commented on a diff in pull request #22964: chore: Migrate /superset/user_slices and /superset/fave_slices to API v1

Posted by "diegomedina248 (via GitHub)" <gi...@apache.org>.
diegomedina248 commented on code in PR #22964:
URL: https://github.com/apache/superset/pull/22964#discussion_r1098972833


##########
superset/charts/api.py:
##########
@@ -914,3 +916,43 @@ def import_(self) -> Response:
         )
         command.run()
         return self.response(200, message="OK")
+
+    @expose("/user_slices/")
+    @expose("/user_slices/<int:user_id>/")

Review Comment:
   mm, would that return favorited slices too?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org