fix: group-detail file_count via explicit M2M, not stored events (#91)#97
fix: group-detail file_count via explicit M2M, not stored events (#91)#97agent-p1p wants to merge 1 commit into
Conversation
group_detail_shell_context() derived file_count from AuditFile.objects.filter(events__group=group), which excludes duplicate-only linked files (zero stored AuditEvent rows for the group but still linked via the AuditFile.groups M2M recorded by create_events). This contradicted every other file-count path (audit_files_for_group, annotated_group_list, group_summary) and the goggles#37 fix, so the group header / Files-tab badge undercounted while the Files tab itself listed the full set. Switch to AuditFile.objects.filter(groups=group), matching the rest of the app. Add a regression assertion to the existing duplicate-heavy re-upload test confirming the shell count equals the Files tab count. Closes #91
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Walkthrough
ChangesFix file_count undercount in group_detail_shell_context
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Ready to review this PR? Stage has broken it down into 2 individual chapters for you:
Chapters generated by Stage for commit 2867abd on Jun 22, 2026 12:35pm UTC. |
Pip adversarial reviewVerdict: no PR-diff blocking findings. Findings:
Reviewed scope:
Verification run:
CI note: GitHub |
Closes #91
Summary
group_detail_shell_context()derived the group's member-log count from stored events (AuditFile.objects.filter(events__group=group)) rather than the explicitAuditFile.groupsM2M. A duplicate-heavy upload whose group events are all deduplicated away stores zeroAuditEventrows for that group, yetcreate_events()still records the file-to-group link on the M2M (audit_file.groups.add(*group_ids)). Soevents__groupis a subset ofgroups, and the shell count could only undercount — the group header ("coalesced from N member log(s)") and the Files-tab badge disagreed with the Files tab listing itself.This contradicted every other file-count path in the app and the goggles#37 fix:
analysis.pyaudit_files_for_group()->filter(groups=group)analysis.pyannotated_group_list()->Count("audit_files_linked", distinct=True)analysis.pygroup_summary()->len(audit_files)(M2M-derived)Fix
One line in
forensics/views.py:events__group=group->groups=group, making the shell count consistent with the rest of the app. Added an explanatory comment referencing #37 and #91.Test
Extended the existing duplicate-heavy re-upload regression test (
AuditLogIngestionTests.test_duplicate_heavy_reupload_keeps_group_link_with_zero_stored_events) with assertions that the shell context'ssummary.file_countandtab_counts.filesboth equal 2 (matching the Files tab), not the undercounted 1.RED/GREEN proven locally: without the fix the new assertion fails
AssertionError: 1 != 2; with the fix it passes.Verification (run locally — goggles CI gates)
uv run python manage.py test— 147 passeduv run ruff check .— cleanuv run ruff format --check .— cleanuv run python manage.py check— no issuesPre-existing master CI breakage (NOT introduced by this PR)
origin/master(94630b0, #87) currently has failing CI due to a migration-graph conflict: two0007_*leaf migrations (0007_auditfile_groupsfrom #80 and0007_add_auditevent_line_hash_engine_indexfrom #87) both depend on0006with no merge migration, somanage.py testaborts withConflicting migrations detected; multiple leaf nodes. Master's own CI run for 94630b0 is red on the "Run tests" step for this reason.Because of this, this PR's CI test step will also fail until a merge migration lands on master. This PR deliberately does not include that merge migration (migrations are a sensitive path and the drift is unrelated to this fix). The local verification above was run with a throwaway merge migration to confirm this fix is correct in isolation; that throwaway is not part of the diff. The master migration drift is being escalated separately.
Sensitive paths
None. Diff is
forensics/views.py(one-line query change + comment) andforensics/tests.py(regression assertions + import). No models, no migrations.Summary by CodeRabbit