Skip to content

Allow single-row translation updates that include key and language - #28001

Merged
ComfortablyCoding merged 8 commits into
directus:mainfrom
suhailopensource:fix/27986-translations-single-row-update
Aug 4, 2026
Merged

ComfortablyCoding merged 8 commits into
directus:mainfrom
suhailopensource:fix/27986-translations-single-row-update

Conversation

@suhailopensource

@suhailopensource suhailopensource commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #27986

Problem

TranslationsService.updateMany rejected legitimate single-row updates that included both key and language, returning a false 400 Duplicate key and language combination. This blocked edits via REST/SDK/Studio and blocked sync/import tools sending the complete record.

Root cause (api/src/services/translations.ts)

  1. The guard used keys.length > 0, so it rejected every single-row update. A single row can't self-collide — only a multi-row update collapsing several rows onto the same key+language should be rejected there.
  2. translationKeyExists() didn't exclude the row(s) being updated, so a resave carrying the row's own key+language matched itself and reported a false duplicate.

Fix

  • Changed the guard to keys.length > 1.
  • Added an excludeKeys argument to translationKeyExists() (.whereNotIn('id', excludeKeys)) and passed the ids being updated, so a row can't collide with itself.

Tests

Added api/src/services/translations.test.ts covering:

The regression test fails with only the guard change and passes once the self-exclusion is added.

Notes

Per discussion on the issue, the Studio only sends changed fields on a resave, so the self-exclusion mainly matters for the import/sync path sending the full record — kept it in to cover that case.

@suhailopensource
suhailopensource force-pushed the fix/27986-translations-single-row-update branch from 1534692 to ba64df6 Compare July 29, 2026 15:56

@ComfortablyCoding ComfortablyCoding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! See comments below

Comment thread api/src/services/translations.ts Resolved
@suhailopensource
suhailopensource force-pushed the fix/27986-translations-single-row-update branch from 93721a3 to 515279d Compare July 29, 2026 16:31
@ComfortablyCoding
ComfortablyCoding marked this pull request as draft July 29, 2026 16:34
Comment thread api/src/services/translations.ts Resolved
@suhailopensource
suhailopensource marked this pull request as ready for review July 29, 2026 17:05

@ComfortablyCoding ComfortablyCoding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second pass review, see comments below.

Comment thread api/src/services/translations.ts Resolved
Comment thread api/src/services/translations.ts Resolved
Comment thread api/src/services/translations.ts Resolved

@ComfortablyCoding ComfortablyCoding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks and congratulations on your first contribution to directus! 🥳

@ComfortablyCoding
ComfortablyCoding merged commit d049129 into directus:main Aug 4, 2026
103 of 139 checks passed
@github-actions github-actions Bot added this to the Next Release milestone Aug 4, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TranslationsService.updateMany rejects any single-row update that includes both key and language

2 participants