From 7a23797de26a275c0a54105292240e908350d99f Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Wed, 9 Oct 2024 17:14:29 +0200 Subject: [PATCH] feat: ignore idempotency hash from old data --- internal/controller/ledger/log_process.go | 8 ++++++-- .../bucket/migrations/19-logs-add-idempotency-hash.sql | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/controller/ledger/log_process.go b/internal/controller/ledger/log_process.go index acd04094a..78e0ead70 100644 --- a/internal/controller/ledger/log_process.go +++ b/internal/controller/ledger/log_process.go @@ -52,8 +52,12 @@ func forgeLog[INPUT any, OUTPUT ledger.LogPayload](ctx context.Context, store St return nil, err } if err == nil { - if computedHash := ledger.ComputeIdempotencyHash(parameters.Input); log.IdempotencyHash != computedHash { - return nil, newErrInvalidIdempotencyInputs(log.IdempotencyKey, log.IdempotencyHash, computedHash) + // notes(gfyrag): idempotency hash should never be empty in this case, but data from previous + // ledger version does not have this field and it cannot be recomputed + if log.IdempotencyHash != "" { + if computedHash := ledger.ComputeIdempotencyHash(parameters.Input); log.IdempotencyHash != computedHash { + return nil, newErrInvalidIdempotencyInputs(log.IdempotencyKey, log.IdempotencyHash, computedHash) + } } return pointer.For(log.Data.(OUTPUT)), nil diff --git a/internal/storage/bucket/migrations/19-logs-add-idempotency-hash.sql b/internal/storage/bucket/migrations/19-logs-add-idempotency-hash.sql index f1eedaa79..fe7709ff5 100644 --- a/internal/storage/bucket/migrations/19-logs-add-idempotency-hash.sql +++ b/internal/storage/bucket/migrations/19-logs-add-idempotency-hash.sql @@ -1,3 +1,2 @@ ---todo: add special traitement on code when value is empty alter table "{{.Bucket}}".logs add column idempotency_hash bytea; \ No newline at end of file