robdiciuccio commented on a change in pull request #8972: [dashboards] New, API 
for Bulk delete
URL: 
https://github.com/apache/incubator-superset/pull/8972#discussion_r368730639
 
 

 ##########
 File path: superset/views/dashboard/api.py
 ##########
 @@ -346,71 +346,68 @@ def multiple_delete(self, **kwargs):  # pylint: 
disable=arguments-differ
                     type: integer
           responses:
             200:
-              description: Dashboard multiple delete
+              description: Dashboard bulk delete
               content:
                 application/json:
                   schema:
                     type: object
                     properties:
                       message:
                         type: string
-                      count:
-                        description: Number of deleted dashboards
-                        type: integer
             401:
               $ref: '#/components/responses/401'
             403:
-              description: Dashboard multiple delete
-              content:
-                application/json:
-                  schema:
-                    type: object
-                    properties:
-                      message:
-                        type: string
-                      count:
-                        description: Number of deleted dashboards
-                        type: integer
+              $ref: '#/components/responses/401'
             404:
               $ref: '#/components/responses/404'
             422:
               $ref: '#/components/responses/422'
             500:
               $ref: '#/components/responses/500'
         """
+        item_ids = kwargs["rison"]
         query = self.datamodel.session.query(Dashboard).filter(
-            Dashboard.id.in_(kwargs["rison"])
+            Dashboard.id.in_(item_ids)
         )
         items = self._base_filters.apply_all(query).all()
         if not items:
             return self.response_404()
-        delete_count = 0
-        status_code = 200
         for item in items:
             try:
                 check_ownership(item)
-                self.datamodel.delete(item, raise_exception=True)
-                delete_count += 1
             except SupersetSecurityException as e:
                 logger.warning(
                     f"Dashboard {item} was not deleted, "
                     f"because the user ({g.user}) does not own it"
                 )
-                status_code = 403
+                return self.response(403, message=_("No dashboards deleted"))
             except SQLAlchemyError as e:
                 return self.response_422(message=str(e))
-        if delete_count == 0:
-            return self.response(
-                status_code, message=_("No dashboards deleted"), 
count=delete_count
-            )
+        # bulk delete, first delete related data
+        for item in items:
+            try:
+                item.slices = []
+                item.owners = []
+                self.datamodel.session.merge(item)
+            except SQLAlchemyError as e:
 
 Review comment:
   Log this error?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to