From 9f107f41b5467c98870eb49976ea793c2c27b52f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 18 Nov 2025 03:44:08 +0000 Subject: [PATCH] fix(api): handle NULL columns in group queries to prevent silent failures Use COALESCE to convert NULL values to empty strings for display_name and description columns in GetGroup, GetGroupByName, and ListGroups functions. This fixes the issue where groups were not displaying because scanning NULL values into Go string types caused silent failures (errors were being silently skipped with continue). --- api/internal/db/groups.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/api/internal/db/groups.go b/api/internal/db/groups.go index 9fded8f5..bc9a472f 100644 --- a/api/internal/db/groups.go +++ b/api/internal/db/groups.go @@ -137,7 +137,8 @@ func (g *GroupDB) CreateGroup(ctx context.Context, req *models.CreateGroupReques func (g *GroupDB) GetGroup(ctx context.Context, groupID string) (*models.Group, error) { group := &models.Group{} query := ` - SELECT g.id, g.name, g.display_name, g.description, g.type, g.parent_id, + SELECT g.id, g.name, COALESCE(g.display_name, '') as display_name, + COALESCE(g.description, '') as description, g.type, g.parent_id, g.created_at, g.updated_at, COUNT(gm.user_id) as member_count FROM groups g LEFT JOIN group_memberships gm ON g.id = gm.group_id @@ -164,7 +165,8 @@ func (g *GroupDB) GetGroup(ctx context.Context, groupID string) (*models.Group, func (g *GroupDB) GetGroupByName(ctx context.Context, name string) (*models.Group, error) { group := &models.Group{} query := ` - SELECT g.id, g.name, g.display_name, g.description, g.type, g.parent_id, + SELECT g.id, g.name, COALESCE(g.display_name, '') as display_name, + COALESCE(g.description, '') as description, g.type, g.parent_id, g.created_at, g.updated_at, COUNT(gm.user_id) as member_count FROM groups g LEFT JOIN group_memberships gm ON g.id = gm.group_id @@ -190,7 +192,8 @@ func (g *GroupDB) GetGroupByName(ctx context.Context, name string) (*models.Grou // ListGroups retrieves all groups with optional filtering func (g *GroupDB) ListGroups(ctx context.Context, groupType string, parentID *string) ([]*models.Group, error) { query := ` - SELECT g.id, g.name, g.display_name, g.description, g.type, g.parent_id, + SELECT g.id, g.name, COALESCE(g.display_name, '') as display_name, + COALESCE(g.description, '') as description, g.type, g.parent_id, g.created_at, g.updated_at, COUNT(gm.user_id) as member_count FROM groups g LEFT JOIN group_memberships gm ON g.id = gm.group_id