Skip to content

Commit

Permalink
Merge pull request #2035 from dandi/fix-empty-logic
Browse files Browse the repository at this point in the history
Fix Dandiset emptiness detection logic
  • Loading branch information
waxlamp authored Sep 23, 2024
2 parents 45f6814 + 1f12409 commit 86ba19c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dandiapi/api/tests/test_dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ def test_dandiset_rest_list(api_client, user, dandiset):
[
('', ['empty', 'draft', 'published', 'erased']),
('?draft=false', ['published', 'erased']),
('?empty=false', ['draft', 'published']),
('?empty=false', ['draft', 'published', 'erased']),
('?draft=true&empty=true', ['empty', 'draft', 'published', 'erased']),
('?empty=true&draft=true', ['empty', 'draft', 'published', 'erased']),
('?draft=false&empty=false', ['published']),
('?draft=false&empty=false', ['published', 'erased']),
],
ids=[
'nothing',
Expand Down
6 changes: 3 additions & 3 deletions dandiapi/api/views/dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ def get_queryset(self):
# Only include dandisets that have assets in their most recent version.
most_recent_version = (
Version.objects.filter(dandiset=OuterRef('pk'))
.order_by('created')
.order_by('-created')
.annotate(asset_count=Count('assets'))[:1]
)
queryset = queryset.annotate(
draft_asset_count=Subquery(most_recent_version.values('asset_count'))
asset_count=Subquery(most_recent_version.values('asset_count'))
)
queryset = queryset.filter(draft_asset_count__gt=0)
queryset = queryset.filter(asset_count__gt=0)
if not show_embargoed:
queryset = queryset.filter(embargo_status='OPEN')
return queryset
Expand Down

0 comments on commit 86ba19c

Please sign in to comment.