fix: throw clear error for non-existent listSearchableFields - #17714
Open
vjymisal0 wants to merge 1 commit into
Open
fix: throw clear error for non-existent listSearchableFields#17714vjymisal0 wants to merge 1 commit into
vjymisal0 wants to merge 1 commit into
Conversation
Previously, referencing a field name in admin.listSearchableFields that does not exist on the collection would not surface any error during development (pnpm dev). In production builds, the same invalid config would cause the search query to hit the database with an unqueryable path, "imploding" the admin List View search with no usable error message to the user. This adds validateListSearchableFields, called during collection sanitization (mirroring the existing validateUseAsTitle pattern), which eagerly throws an InvalidConfiguration error naming the offending field and collection as soon as the config is loaded - consistently in both dev and production. Fixes payloadcms#14904
Author
|
Update: dependencies finished installing in my sandbox, so I was able to run the tests locally after all. All 4 new tests pass, and the existing |
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.
What?
Adds validation that throws a clear
InvalidConfigurationerror whenadmin.listSearchableFieldson a collection config references a field name that does not exist on that collection.Why?
Fixes #14904.
Previously, referencing a non-existent field name in
admin.listSearchableFieldsproduced no error at all inpnpm dev, and in production builds it "imploded" the admin List View search with no usable error message - the actual failure ("The following path cannot be queried: <field>") only ever showed up in server logs, never reaching the user.How?
Added
validateListSearchableFieldsinpackages/payload/src/collections/config/listSearchableFields.ts, mirroring the existingvalidateUseAsTitleprecedent in the same directory. It flattens the collection's top-level fields and checks each entry inadmin.listSearchableFields(skipping the implicitidfield, and only checking the top-level segment of dotted/relationship paths) exists on the collection, throwingInvalidConfigurationnaming the offending field and collection slug if not.This is called from
sanitizeCollectionright aftervalidateUseAsTitle, so it runs unconditionally at config-sanitization time in both dev and production - no more environment-dependent failure mode.Test plan
Added
packages/payload/src/collections/config/listSearchableFields.spec.ts(mirrorsuseAsTitle.spec.ts), covering:idfieldlistSearchableFieldsis undefinedNote:
pnpm installin this sandbox environment was intermittently failing on Windows temp-path EPERM/network timeout issues while I prepared this PR, so I could not get a green localvitestrun to paste here. The test code itself directly follows the existing, currently-passinguseAsTitle.spec.tspattern in the same file, using the samesanitizeCollectionharness.Fixes #14904