Andrey Antukh 64a51e86fd
🐛 Fix files blocked by dangling child references in migrations (#12936) (#12979)
The 0033-normalize-main-instance-names migration walks the shape tree
following the :shapes vectors. When a parent listed a child id missing
from the container :objects map (a dangling reference), the traversal
stored the nil child into :objects, creating a nil key that made
check-file-data reject the whole file: get-file answered 500 "invalid
file data" and the file could not be opened or migrated further.

Fix it in two parts:

- 0033 returns the container untouched when a listed child does not
  exist, so the traversal never stores a nil shape.
- The append-only migration 0035-fix-dangling-children prunes from
  every :shapes vector, in pages and components, the ids absent from
  the owning container :objects map, logging each fix at trace level.
  It mirrors 0032-fix-children-not-in-parent, which repairs the
  opposite inconsistency.

Both parts are needed: 0033 runs before the repair migration, so
without the guard the same file fails again in the same migrate call.

Add regression tests for the traversal guard and for the repair
migration, and record in mem:clojure/logging the convention that
:hints start lowercase.

Closes #12936

AI-assisted-by: qwen3.8-flash
2026-11-12 09:41:49 +01:00

1.2 KiB

Clojure Logging Conventions

Structured logging through app.common.logging (l/trc/l/dbg/l/info/l/wrn/l/error/l/fatal): :hint carries the human-readable message, every other datum goes in its own keyword field (:id, :container, :removed, ...).

  • :hint values start lowercase: "fix dangling children", not "Fix dangling children". Uppercase-first hints exist as legacy (~57 occurrences, the densest in backend/src; also l/trc in migration legacy-28 and log/error in app.common.files.repair) — do not copy them, and do not mass-rewrite them unless the surrounding code needs the change.
  • A name that requires uppercase (an env var like PENPOT_MEDIA_PROCESSING_SERVICE_URI, an acronym like MCP or LDAP) stays uppercase inside an otherwise lowercase sentence.
  • Repair work done by a file migration logs at l/trc, only when it changes something, and with the ids it touched: the house style of migrations.cljc (legacy-28 precedes; the file has no warn/info lines). The shipped log4j2.xml pins the app logger to info (static file, monitorInterval="60"), so those trace lines appear only after the operator raises the level; the durable record of a repaired file is the migration id in its :migrations.