Skip to content

Hotfix v0.3.2: Inline edit silently failing on non-id primary keys (#44)#54

Merged
smartlabsAT merged 2 commits into
mainfrom
hotfix/v0.3.2-issue-44
May 9, 2026
Merged

Hotfix v0.3.2: Inline edit silently failing on non-id primary keys (#44)#54
smartlabsAT merged 2 commits into
mainfrom
hotfix/v0.3.2-issue-44

Conversation

@smartlabsAT
Copy link
Copy Markdown
Owner

@smartlabsAT smartlabsAT commented May 9, 2026

Summary

Closes #44.

handleUpdate and handleBooleanToggle in EditableCellRelational.vue detected the primary key by name-pattern matching:

const primaryKey = Object.keys(props.item).find((key) => key === 'id' || key.endsWith('_id'));
if (primaryKey) { emit('update', props.item[primaryKey], ...); }

When the primary key has a different name (code, slug, uuid, sku, …), the lookup returns undefined, the if-guard short-circuits, no event is emitted, and the inline edit silently never reaches the database — exactly the behaviour reported in #44.

The fix uses the primaryKeyField computed property that already exists in the same component. Its value is sourced from useCollection().primaryKeyField in the parent (super-table.vue) and passed in as primary-key-field-name, so it is always the schema-authoritative PK field name.

Why the same pattern was a latent data-corruption risk

When an item carries both a real primary key (e.g. code = "PROD-A1") and an unrelated field literally named id (or ending in _id like parent_id), the previous heuristic preferred those over the actual PK. The PATCH would then be dispatched against \/items\/<collection>\/<id_value> instead of \/items\/<collection>\/<pk_value> — at best a 404, at worst an update to an unrelated record. The new code reads the schema-authoritative PK name, so this misdirection is no longer possible.

Verification

Reproduced the original bug, applied the fix, and re-tested manually against the running Directus instance:

Scenario Result
code PK + inline string edit PATCH /items/test_bug_44/ITEM-001 → 200, DB updated
code PK + direct boolean toggle PATCH /items/test_bug_44/ITEM-002 → 200, DB updated
id PK (regression) PATCH /items/test_bug_44_id/1 → 200, DB updated
sku PK with extra id=999 and parent_id=42 fields PATCH /items/test_bug_44_evil/PROD-A1 → 200, DB updated

Quality checks pass (pnpm run quality):

  • vue-tsc --noEmit
  • eslint . --max-warnings=0
  • prettier --check

Test plan

  • Build the extension and load Directus
  • On a collection whose primary key is not id (e.g. code, uuid), switch to Super Table and enable inline editing
  • Edit a string field inline, click save → expect a PATCH /items/<collection>/<pk-value> and the value to persist
  • Enable Direct Boolean Toggle, click a boolean cell → expect the same PATCH flow
  • On any id-keyed collection, repeat both interactions → expect no regression

handleUpdate and handleBooleanToggle in EditableCellRelational.vue
detected the primary key by name pattern matching
(key === 'id' || key.endsWith('_id')), which produced no result on
collections whose primary key uses a different name (code, slug, uuid,
sku, ...). The emit was skipped silently and the inline edit never
reached the database.

Both handlers now read the primary key field name from the
primaryKeyField computed property, which the parent component sources
from the Directus schema via useCollection. This also closes a latent
risk: when an item carried both the real primary key and an unrelated
field named id or ending in _id, the previous heuristic could pick the
wrong column and dispatch the PATCH against an unrelated record.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Quality Check Results

TypeScript Type Check

Passed - No type errors found

ESLint

Passed - No linting errors

Prettier Format Check

Passed - Code is properly formatted

Build

Passed - Extension builds successfully


Updated: 2026-05-09T17:07:49.525Z

@smartlabsAT smartlabsAT merged commit b2ba0ea into main May 9, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot inline edit fields when the collection key is not id

1 participant