Fix: notificação enviada para hábito deletado
TLDR: Adiciona o guard
habit__deleted_at__isnull=Truena query de notificações para excluir hábitos soft-deletados.
Contexto
HabitNotificationService.send_pending_notifications() consulta HabitExecution filtrando por habit__status='active'. Quando um hábito é soft-deletado (deleted_at é preenchido), o campo status permanece 'active'. Como a query atravessa o join da FK diretamente — sem passar pelo manager de soft-deletion Habit.objects — hábitos deletados continuam sendo encontrados, causando envio de push depois da deleção.
Objetivos
- Parar de enviar push notifications para hábitos soft-deletados.
Fora de escopo
— (não registrado na spec original)
Mudanças
apps/habits/services.py— adicionarhabit__deleted_at__isnull=Trueao filtro do queryset emHabitNotificationService.send_pending_notifications()tests/habits/test_notification_service.py— adicionar o testetest_no_notification_for_deleted_habit
Como verificar
- Rodar
make test test=tests/habits/test_notification_service.py— todos os testes verdes - O novo teste
test_no_notification_for_deleted_habitfalha antes do fix e passa depois
Documentação
- learnings/habits_notification_for_deleted_habit.md — joins por FK não passam pelo manager de soft-deletion e exigem guard explícito de
deleted_at__isnull=True