Fix PostgreSQL query parameter encoding for notification hour check

The WHERE clause with `? = ?` comparing two bound parameters caused
PostgreSQL to fail with "unable to encode into text format" error.
Fixed by moving the comparison to Go code and building the query
conditionally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-07 09:14:41 -06:00
parent dd16019ce2
commit 66c8fe9428

View File

@@ -71,12 +71,21 @@ func (h *Handler) HandleTaskReminder(ctx context.Context, task *asynq.Task) erro
// Step 1: Find users who should receive notifications THIS hour // Step 1: Find users who should receive notifications THIS hour
// Users with custom hour matching current hour, OR users with no custom hour when current hour is system default // Users with custom hour matching current hour, OR users with no custom hour when current hour is system default
var eligibleUserIDs []uint var eligibleUserIDs []uint
err := h.db.Model(&models.NotificationPreference{}).
// Build query based on whether current hour is system default
query := h.db.Model(&models.NotificationPreference{}).
Select("user_id"). Select("user_id").
Where("task_due_soon = true"). Where("task_due_soon = true")
Where("(task_due_soon_hour = ? OR (task_due_soon_hour IS NULL AND ? = ?))",
currentHour, currentHour, systemDefaultHour). if currentHour == systemDefaultHour {
Pluck("user_id", &eligibleUserIDs).Error // Current hour is the system default, so include users with custom hour OR no custom hour (NULL)
query = query.Where("(task_due_soon_hour = ? OR task_due_soon_hour IS NULL)", currentHour)
} else {
// Current hour is not system default, so only include users with this specific custom hour
query = query.Where("task_due_soon_hour = ?", currentHour)
}
err := query.Pluck("user_id", &eligibleUserIDs).Error
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to query eligible users for task reminders") log.Error().Err(err).Msg("Failed to query eligible users for task reminders")
@@ -175,12 +184,21 @@ func (h *Handler) HandleOverdueReminder(ctx context.Context, task *asynq.Task) e
// Step 1: Find users who should receive notifications THIS hour // Step 1: Find users who should receive notifications THIS hour
// Users with custom hour matching current hour, OR users with no custom hour when current hour is system default // Users with custom hour matching current hour, OR users with no custom hour when current hour is system default
var eligibleUserIDs []uint var eligibleUserIDs []uint
err := h.db.Model(&models.NotificationPreference{}).
// Build query based on whether current hour is system default
query := h.db.Model(&models.NotificationPreference{}).
Select("user_id"). Select("user_id").
Where("task_overdue = true"). Where("task_overdue = true")
Where("(task_overdue_hour = ? OR (task_overdue_hour IS NULL AND ? = ?))",
currentHour, currentHour, systemDefaultHour). if currentHour == systemDefaultHour {
Pluck("user_id", &eligibleUserIDs).Error // Current hour is the system default, so include users with custom hour OR no custom hour (NULL)
query = query.Where("(task_overdue_hour = ? OR task_overdue_hour IS NULL)", currentHour)
} else {
// Current hour is not system default, so only include users with this specific custom hour
query = query.Where("task_overdue_hour = ?", currentHour)
}
err := query.Pluck("user_id", &eligibleUserIDs).Error
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to query eligible users for overdue reminders") log.Error().Err(err).Msg("Failed to query eligible users for overdue reminders")