veza/veza-backend-api/internal/core
senke b5281bec98
Some checks failed
Frontend CI / test (push) Failing after 0s
fix(marketplace): wrap DELETE+loop-CREATE in transaction
Two seller-facing mutations followed the same buggy pattern:

  1. s.db.Delete(...all existing rows...)   ← committed immediately
  2. for range inputs { s.db.Create(new) }  ← if any fails mid-loop,
                                              deletes are already
                                              committed → product
                                              left in an inconsistent
                                              state (0 images or
                                              0 licenses) until the
                                              seller retries.

Affected:
  - Service.UpdateProductImages  — 0 images = product page broken
  - Service.SetProductLicenses   — 0 licenses = product unsellable

Fix: wrap each function body in s.db.WithContext(ctx).Transaction,
using tx.* instead of s.db.* throughout. Rollback on any error in
the loop restores the previous images/licenses.

Side benefit: ctx is now propagated into the reads (WithContext on
the transaction root), so timeout middleware applies to the whole
sequence — previously the reads bypassed request timeouts.

Tests: ./internal/core/marketplace/ green (0.478s). go build + vet
clean.

Scope:
  - Subscription service already uses Transaction() for multi-step
    mutations (service.go:287, :395); its single-row Saves
    (scheduleDowngrade, CancelSubscription) are atomic by nature.
  - Wishlist / cart / education / discover core services audited —
    no matching DELETE+LOOP-CREATE pattern found.
  - Single-row mutations (AddProductPreview, UpdateProduct) don't
    need wrapping — atomic in Postgres.

Refs: AUDIT_REPORT.md §4.4 "Transactions insuffisantes" + §9 #3
(critical: marketplace/service.go transactions manquantes).
Narrower than the original audit flagged — real bugs were these 2
functions, not the broader "1050+" region.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 09:57:50 +02:00
..
admin feat(v0.11.3): F421-F424 admin platform handler and routes 2026-03-10 18:19:45 +01:00
analytics fix(v0.12.6): apply all pentest remediations — 36 findings across 36 files 2026-03-14 00:44:46 +01:00
auth fix(backend,infra): send real verification emails + fail-loud in prod 2026-04-16 14:52:46 +02:00
collaboration adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
connecterrors feat(marketplace): stripe reversal error disambiguation + CHECK constraint + E2E — v1.0.7 item B day 3 2026-04-18 02:12:03 +02:00
discover style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
distribution fix(distribution,audit): propagate ErrSubscriptionNoPayment to handler + P0.12 closure date + E2E regression TODO 2026-04-17 12:43:21 +02:00
education style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
feed feat(v0.10.1): Tags & Genres discover - F351-F355 2026-03-09 01:52:56 +01:00
marketplace fix(marketplace): wrap DELETE+loop-CREATE in transaction 2026-04-21 09:57:50 +02:00
moderation feat(v0.11.2): F411-F420 moderation handler and routes 2026-03-10 17:49:51 +01:00
social fix(v0.12.6): apply all pentest remediations — 36 findings across 36 files 2026-03-14 00:44:46 +01:00
subscription chore(release): v1.0.6.2 — subscription payment-gate bypass hotfix 2026-04-17 12:21:53 +02:00
track feat(backend,web): single source of truth for upload-size limits 2026-04-16 19:37:37 +02:00