From 0525edd3bbc03c631f871552011751ae94f58e65 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 9 Nov 2026 14:40:58 +1100 Subject: [PATCH] fix(postgres): blocker-changed marks only the org whose resource changed (#1839) --- .../infrastructure/postgres/postgresdb/tasks.sql.go | 11 ++++++++--- internal/infrastructure/postgres/queries/tasks.sql | 2 +- internal/infrastructure/postgres/resources.go | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/infrastructure/postgres/postgresdb/tasks.sql.go b/internal/infrastructure/postgres/postgresdb/tasks.sql.go index 4602d4672..d8acdab99 100644 --- a/internal/infrastructure/postgres/postgresdb/tasks.sql.go +++ b/internal/infrastructure/postgres/postgresdb/tasks.sql.go @@ -869,14 +869,19 @@ func (q *Queries) LockTaskStatus(ctx context.Context, id int64) (string, error) const markBlockerChanged = `-- name: MarkBlockerChanged :execrows UPDATE tasks SET park_reason = park_reason || ' [blocker changed]', updated_at = now() -WHERE status = 'parked' AND park_blocker = ANY($1::text[]) +WHERE status = 'parked' AND org_id = $1 AND park_blocker = ANY($2::text[]) AND park_reason NOT LIKE '%[blocker changed]' ` +type MarkBlockerChangedParams struct { + OrgID string + Blockers []string +} + // A parked task that names one of these blockers is flagged once, so the // operator sees the resource it waited on was edited; retry stays theirs. -func (q *Queries) MarkBlockerChanged(ctx context.Context, blockers []string) (int64, error) { - result, err := q.db.Exec(ctx, markBlockerChanged, blockers) +func (q *Queries) MarkBlockerChanged(ctx context.Context, arg MarkBlockerChangedParams) (int64, error) { + result, err := q.db.Exec(ctx, markBlockerChanged, arg.OrgID, arg.Blockers) if err != nil { return 0, err } diff --git a/internal/infrastructure/postgres/queries/tasks.sql b/internal/infrastructure/postgres/queries/tasks.sql index 769c263ad..37d0bdb36 100644 --- a/internal/infrastructure/postgres/queries/tasks.sql +++ b/internal/infrastructure/postgres/queries/tasks.sql @@ -336,5 +336,5 @@ RETURNING *; -- operator sees the resource it waited on was edited; retry stays theirs. UPDATE tasks SET park_reason = park_reason || ' [blocker changed]', updated_at = now() -WHERE status = 'parked' AND park_blocker = ANY(sqlc.arg(blockers)::text[]) +WHERE status = 'parked' AND org_id = sqlc.arg(org_id) AND park_blocker = ANY(sqlc.arg(blockers)::text[]) AND park_reason NOT LIKE '%[blocker changed]'; diff --git a/internal/infrastructure/postgres/resources.go b/internal/infrastructure/postgres/resources.go index 34b7a7603..e8bebabef 100644 --- a/internal/infrastructure/postgres/resources.go +++ b/internal/infrastructure/postgres/resources.go @@ -147,7 +147,7 @@ func (s *Resources) PutResource(ctx context.Context, write storecontract.Resourc return storecontract.Resource{}, err } if blockers := blockersFixedBy(write.Kind); len(blockers) > 0 { - if _, err := queries.MarkBlockerChanged(ctx, blockers); err != nil { + if _, err := queries.MarkBlockerChanged(ctx, postgresdb.MarkBlockerChangedParams{OrgID: write.OrgID, Blockers: blockers}); err != nil { return storecontract.Resource{}, err } }