@@ -888,7 +888,7 @@ async def delete(self):
888
888
889
889
async def delete_tree (self , external_only = True ):
890
890
"""
891
- Delete a Node and of the Nodes beneath it in the tree.
891
+ Delete the Nodes beneath a Node in the tree.
892
892
893
893
That is, delete all Nodes that have this Node as an ancestor, any number
894
894
of "generators" up.
@@ -902,11 +902,18 @@ async def delete_tree(self, external_only=True):
902
902
if external_only :
903
903
count_int_asset_statement = (
904
904
select (func .count (orm .Asset .data_uri ))
905
- .filter (
906
- orm .Asset .data_sources .any (
907
- orm .DataSource .management != Management .external
908
- )
905
+ .select_from (orm .Asset )
906
+ .join (
907
+ orm .DataSourceAssetAssociation ,
908
+ orm .DataSourceAssetAssociation .asset_id == orm .Asset .id ,
909
+ )
910
+ .join (
911
+ orm .DataSource ,
912
+ orm .DataSource .id
913
+ == orm .DataSourceAssetAssociation .data_source_id ,
909
914
)
915
+ .join (orm .Node , orm .Node .id == orm .DataSource .node_id )
916
+ .filter (orm .DataSource .management != Management .external )
910
917
.filter (condition )
911
918
)
912
919
count_int_assets = (
@@ -923,6 +930,7 @@ async def delete_tree(self, external_only=True):
923
930
# TODO Deal with Assets belonging to multiple DataSources.
924
931
asset_ids_to_delete = (
925
932
select (orm .Asset .id )
933
+ .select_from (orm .Asset ) # Explicitly define the starting point
926
934
.join (
927
935
orm .DataSourceAssetAssociation ,
928
936
orm .DataSourceAssetAssociation .asset_id == orm .Asset .id ,
0 commit comments