fix(server): make workflow-core + person-avatar upgrade commands v2-safe (#24724)
## Context
`#24692` removed `IS_ORM_V2_READ_PATH_ENABLED` and collapsed to the v2
path: `GlobalWorkspaceOrmManager.getRepository` now always routes to the
v2 datasource, and
`WorkspaceORMEntityMetadatasCacheService.computeForCache` returns `[]`
unconditionally (the v1 `GlobalWorkspaceDataSource` metadata is no
longer built).
Several workspace **upgrade commands** still relied on v1 behavior and
break under this. It wasn't caught because the cross-version-upgrade
smoke test only runs on release tags — cutting one off `main` surfaced
it (`staging-ci` failed at `BackfillWorkflowVersionToCore` and then
`MigratePersonAvatarUrlToAvatarFile`).
## Two incompatibilities fixed
**1. Missing-object guards only caught the v1 error type.**
Backfill/repair commands that skip when a workspace predates an object
caught `EntityMetadataNotFoundError` (thrown by v1 `getMetadata`). The
v2 datasource instead throws `TwentyOrmV2Exception(UNKNOWN_OBJECT)`, so
the guard missed it and the upgrade failed. Added a shared
`isWorkspaceObjectNotFoundError` predicate covering both error types and
used it in the four affected commands:
- `2-20 backfill-workflow-version-to-core`
- `2-22 backfill-workflow-version-core-links`
- `2-23 backfill-workflow-core-links`
- `2-28 repair-orphan-core-workflow-versions`
**2. Reading through the iterator's raw v1 datasource.**
`MigratePersonAvatarUrlToAvatarFile` read persons via
`dataSource.getRepository('person')`, where `dataSource` is the
iterator's `GlobalWorkspaceDataSource`. Since `computeForCache` now
returns `[]`, that path throws `EntityMetadataNotFoundError: No metadata
for "person"` **even when the person object exists** (it failed on the
seed workspace). Routed the read through
`globalWorkspaceOrmManager.getRepository` (v2) instead — the command
already runs inside the iterator's `executeInWorkspaceContext`.
## Validation
Validated on the `v2.34.x` release line: these exact fixes took
`staging-ci` (build + cross-version-upgrade smoke test) from failing to
**green**. This PR brings them to `main`.
Note: the 2-9 AI-model-preferences command also matches
`dataSource.getRepository` but reads a **core** entity
(`KeyValuePairEntity`) on the core datasource, so it's unaffected and
left as-is.
<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/24724?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. --> C
Charles Bochet committed
bdc96186ce7b62300e6b5f455cae1afded5cfb2f
Parent: 56864c5
Committed by GitHub <noreply@github.com>
on 8/25/2026, 6:31:48 AM