Skip to content

Fix Focus Queue filter counts stuck at 0 or 1 - #403

Merged
dholbach merged 1 commit into
mainfrom
fix/focus-queue-filter-counts
Sep 1, 2026
Merged

Fix Focus Queue filter counts stuck at 0 or 1#403
dholbach merged 1 commit into
mainfrom
fix/focus-queue-filter-counts

Conversation

@dholbach

@dholbach dholbach commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • /focus filter pill counts were showing 0 or 1 for every task type instead of the real count
  • Root cause: _task_types_with_counts() aggregated (.values().annotate(Count(...))) over a queryset that still carried its display .order_by("due_today_rank", "priority_rank", "created_at"); Django folds those order-by columns into the implicit GROUP BY, splitting each task_type group down to near-unique rows
  • Fix: clear the inherited ordering with .order_by() before aggregating

Test plan

  • Strengthened test_task_type_counts_unaffected_by_active_filter to create two tasks of the same type (previous version only created one per type, so it couldn't distinguish correct behavior from the bug)
  • Verified the strengthened test fails on the old code (1 != 2) and passes with the fix
  • ./dev.py test my_practice.tests.test_views_focus_queue my_practice.tests.test_sync_focus_queue_tasks my_practice.tests.test_weekly_focus_widget — all pass

🤖 Generated with Claude Code

https://claude.ai/code/session_01DqEbdJPKgXjFrYGAWByQD8

_task_types_with_counts() aggregated over a queryset that still carried
its display .order_by("due_today_rank", "priority_rank", "created_at").
Django folds those columns into the implicit GROUP BY once .values()
.annotate() follows, so groups split on created_at/rank instead of just
task_type — collapsing every pill count to 0 or 1. Clear the inherited
ordering with .order_by() before aggregating.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DqEbdJPKgXjFrYGAWByQD8
@dholbach
dholbach merged commit cec6478 into main Sep 1, 2026
2 checks passed
@dholbach
dholbach deleted the fix/focus-queue-filter-counts branch September 1, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant