From bc2238877643955cdd2ef36d2552ab1dacc94172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Tejero=20Cantero?= Date: Thu, 13 Aug 2026 00:58:39 +0200 Subject: [PATCH] :bug: Decode snapshot metadata before resolving storage-backed data --- backend/src/app/binfile/common.clj | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/src/app/binfile/common.clj b/backend/src/app/binfile/common.clj index cf1ae7bc84..beaae575b8 100644 --- a/backend/src/app/binfile/common.clj +++ b/backend/src/app/binfile/common.clj @@ -310,30 +310,41 @@ pipeline (which always blob-decodes) is unaffected." [{:keys [::db/conn] :as cfg} {:keys [id] :as file} decode?] (let [branch (db/get* conn :file-branch {:branch-file-id id}) + _ (when (nil? branch) (ex/raise :type :not-found :code :branch-metadata-missing :hint "branch metadata not found for branch file" :file-id id)) + base (db/get-with-sql cfg [sql:get-branch-base-snapshot (:source-file-id branch) (:base-snapshot-id branch) (ct/now)] {::db/remove-deleted false}) + _ (when (nil? base) (ex/raise :type :not-found :code :base-snapshot-missing :hint "the branch merge-base snapshot cannot be resolved" :file-id id)) + + ;; same decode `fsnap/get-snapshot` applies: storage-backed + ;; snapshots carry the storage ref inside :metadata, so it must + ;; be decoded before `resolve-file-data` can fetch the object base (-> base + (d/update-when :metadata fdata/decode-metadata) (fdata/resolve-file-data cfg) (fdata/decode-file-data cfg)) + rows (db/exec! conn [sql:get-branch-changes id]) + data (reduce (fn [data {:keys [changes]}] (cpc/process-changes data (blob/decode changes))) (:data base) rows) + data (if decode? data (blob/encode data))] (assoc file :data data)))