john-bodley commented on code in PR #24894:
URL: https://github.com/apache/superset/pull/24894#discussion_r1286143273
##########
superset/daos/chart.py:
##########
@@ -41,16 +41,14 @@ class ChartDAO(BaseDAO[Slice]):
@classmethod
def delete(cls, items: Slice | list[Slice], commit: bool = True) -> None:
- item_ids = [item.id for item in get_iterable(items)]
Review Comment:
@jfrag1 if we're removing the bulk delete logic, i.e., deleting outside of
the ORM, then I think there's merit in removing the entire function and falling
back to `BaseDAO.delete`.
##########
tests/integration_tests/datasets/api_tests.py:
##########
@@ -1711,12 +1712,15 @@ def test_bulk_delete_dataset_items(self):
assert rv.status_code == 200
expected_response = {"message": f"Deleted {len(datasets)} datasets"}
assert data == expected_response
+ deleted_datasets = datasets
datasets = (
db.session.query(SqlaTable)
.filter(SqlaTable.table_name.in_(self.fixture_tables_names))
.all()
)
assert datasets == []
+ for dataset in deleted_datasets:
+ setattr(dataset, "_deleted", True)
Review Comment:
This approach doesn't see right, i.e., we shouldn't need to be
setting/getting hidden attributes. If I were you, I would re-evaluate the
failing tests and see what the issue is. Maybe the results weren't flushed or
committed?
##########
superset/daos/dataset.py:
##########
@@ -360,42 +359,6 @@ def create_metric(
"""
return DatasetMetricDAO.create(properties, commit=commit)
- @classmethod
- def delete(
- cls,
- items: SqlaTable | list[SqlaTable],
- commit: bool = True,
- ) -> None:
- """
- Delete the specified items(s) including their associated relationships.
-
- Note that bulk deletion via `delete` does not dispatch the
`after_delete` event
- and thus the ORM event listener callback needs to be invoked manually.
-
- :param items: The item(s) to delete
- :param commit: Whether to commit the transaction
- :raises DAODeleteFailedError: If the deletion failed
- :see: https://docs.sqlalchemy.org/en/latest/orm/queryguide/dml.html
- """
-
- try:
- db.session.query(SqlaTable).filter(
- SqlaTable.id.in_(item.id for item in get_iterable(items))
- ).delete(synchronize_session="fetch")
-
- connection = db.session.connection()
- mapper = next(iter(cls.model_cls.registry.mappers)) # type: ignore
-
- for item in get_iterable(items):
Review Comment:
Per the PR description this method actually _should_ handle bulk deletion
correctly.
##########
superset/daos/dashboard.py:
##########
@@ -185,17 +185,15 @@ def update_charts_owners(model: Dashboard, commit: bool =
True) -> Dashboard:
@classmethod
def delete(cls, items: Dashboard | list[Dashboard], commit: bool = True)
-> None:
- item_ids = [item.id for item in get_iterable(items)]
Review Comment:
See my previous comment.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]