veza/veza-backend-api/internal
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
..
api chore(cleanup): remove 3 deprecated handlers from internal/api/handlers/ 2026-04-21 09:50:43 +02:00
common v0.9.2 2026-03-05 19:27:34 +01:00
config feat(middleware): wire UserRateLimiter into AuthMiddleware (BE-SVC-002) 2026-04-21 09:52:07 +02:00
core fix(marketplace): wrap DELETE+loop-CREATE in transaction 2026-04-21 09:57:50 +02:00
database v0.9.4 2026-03-05 23:03:43 +01:00
dto Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy 2026-02-14 17:23:32 +01:00
elasticsearch style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
email refactor(backend,infra): unify SMTP env schema on canonical SMTP_* names 2026-04-16 20:44:09 +02:00
errors v0.9.8 2026-03-06 19:13:16 +01:00
eventbus fix(eventbus): log RabbitMQ publish failures instead of silent drop 2026-04-16 20:50:51 +02:00
features adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
handlers feat(marketplace): async stripe connect reversal worker — v1.0.7 item B day 2 2026-04-17 15:34:29 +02:00
infrastructure v0.9.4 2026-03-05 23:03:43 +01:00
integration style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
interfaces adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
jobs feat(webhooks): persist raw hyperswitch payloads to audit log — v1.0.7 item E 2026-04-18 02:44:58 +02:00
logging style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
metrics v0.9.4 2026-03-05 23:03:43 +01:00
middleware feat(middleware): wire UserRateLimiter into AuthMiddleware (BE-SVC-002) 2026-04-21 09:52:07 +02:00
models feat(backend,web): self-service creator role upgrade via /settings 2026-04-16 18:35:07 +02:00
monitoring feat(metrics): ledger-health gauges + alert rules — v1.0.7 item F 2026-04-18 03:40:14 +02:00
pagination v0.9.8 2026-03-06 19:13:16 +01:00
recovery chore(v0.102): consolidate remaining changes — docs, frontend, backend 2026-02-20 13:02:12 +01:00
repositories fix(v0.12.6.1): remediate 2 CRITICAL + 10 HIGH + 1 MEDIUM pentest findings 2026-03-12 05:40:53 +01:00
resilience chore: consolidate CI, E2E, backend and frontend updates 2026-02-17 16:43:21 +01:00
response fix: stabilize builds, tests, and lint across all stacks 2026-04-05 16:48:07 +02:00
security refactor(backend): replace 40 fmt.Printf calls with zap structured logging 2026-02-22 17:44:38 +01:00
services fix(webhooks): bump MaxWebhookPayloadBytes 64KB → 256KB — v1.0.7 pre-rc1 (task #44) 2026-04-18 04:05:16 +02:00
shutdown incus deployement fully implemented, Makefile updated and make fmt ran 2026-01-13 19:47:57 +01:00
testutils ci: retire legacy backend-ci.yml, centralize Docker probe in SkipIfNoIntegration 2026-04-15 16:12:45 +02:00
tracing incus deployement fully implemented, Makefile updated and make fmt ran 2026-01-13 19:47:57 +01:00
types feat(profile): add profile privacy toggle (B3) 2026-02-20 15:10:02 +01:00
upload [INT-015] int: Add file upload format standardization 2025-12-25 15:40:01 +01:00
utils fix(v0.12.6): apply all pentest remediations — 36 findings across 36 files 2026-03-14 00:44:46 +01:00
validators feat(v0.13.3): complete - Polish Sécurité Avancée 2026-03-13 10:09:01 +01:00
websocket style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
workers fix(backend): J4 — GDPR-compliant hard delete with Redis and ES cleanup 2026-04-15 12:25:39 +02:00