Repository navigation
fix: don't reject filled required manyToOne relations when scheduling - #240
Merged
Merged
Conversation
The required-relation check before scheduling a publish decided whether a
relation holds an array with `relation.includes('many')`, which also matches
manyToOne. A filled manyToOne relation (a single object) was then reported as
"This field is required", so such entries could never be scheduled.
- Use `relations.isAnyToMany` from @strapi/utils plus morphMany/morphToMany
to detect to-many relations; to-one relations are checked for null
- Playground: add an Author type and a required manyToOne `author` relation
on Article as regression coverage, seeded for the draft articles
- CLAUDE.md: document that the playground relation must stay required
TMSchipper
force-pushed
the
bugfix/required-to-one-relation-validation
branch
from
November 14, 2026 13:08
bb85097 to
813a63f
Compare
TMSchipper
added a commit
that referenced
this pull request
Nov 15, 2026
- Add regression tests for filled/empty required to-one, to-many and morph relations (#240), deep populate and component/dynamic zone paths - Run the action service and controller on Strapi's real core service and controller (tests/setup.js loads the CommonJS build of @strapi/strapi) - Test helper: content-manager services by name, chainable populate-builder, strapi.contentTypes, a cron fake that behaves like Strapi's - Tighten the publication service, controller, route, registry and bootstrap tests; add admin translation helper tests; include admin utils in coverage - Lint vitest.config.mjs, group vitest updates in Dependabot, run the unit tests in the publish workflow, document the test scope and Node ^22.12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Scheduling a publish for an entry with a required manyToOne relation always failed, even when the relation was filled:
collectRequiredMissinginserver/middlewares/validate-before-scheduling.jsdecided whether a relation holds an array with a fallbackattr.relation.toLowerCase().includes('many'). That also matchesmanyToOne, so the populated single object was checked as an array (!Array.isArray(value)→ "empty") and the action could never be scheduled.Fix
relations.isAnyToMany(attr)from@strapi/utils(the same check the Content Manager uses to populate relations) instead of string matching.morphMany,morphToMany) are added explicitly, becauseisAnyToManyonly coversoneToMany/manyToMany.manyToOne,oneToOne,morphOne,morphToOne) are now checked fornull/undefined; to-many relations for an empty array. Empty required relations are still rejected.Regression coverage (playground)
bugfix/212-restrict-plugin-users-without-permission, so they won't conflict.requiredmanyToOneauthorrelation; the seed creates an author and connects it to the draft articles.CLAUDE.mddocuments that this relation must stay required.Testing
yarn playground:smokewithout the fix: fails with theauthorvalidation error above (bug reproduced).yarn lint:check,yarn build,yarn verify✔yarn playground:smoke(fresh DB, incl. admin build) ✔: publish/unpublish of Article + Homepage, actions removed, all four hooks ran400with an error onauthor; article with author →201yarn consumer-testwith Strapiminimumandcurrent✔ (Strapi 5.34.0 and 5.61.0, Node 22)Notes
yarn playground:reset(or set an author) before scheduling those.article/schema.json,playground/src/index.js); whichever merges second needs a small conflict resolution. After both are merged,authorstays required.strictRelationsvalidator option instead of classifying relation types.