Prevent duplicate file counts for single-file upload fields #461
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
Fixes duplicate file count validation errors when submitting single-file upload fields via GraphQL multipart requests. Single-file fields now correctly skip the multi-upload pipeline and only use
$_FILES, preventing files from being counted twice.Why
When submitting single-file upload fields via GraphQL multipart requests, files were being processed through both mechanisms:
$_FILES- Files from multipart form data (handled byFileUploadValuesInput)gform_uploaded_files- Files processed through the multi-upload pipeline ininitialize_files()This caused Gravity Forms'
get_submission_files()method to find the same file in both:$files['existing']- fromGFFormsModel::$uploaded_files(populated viagform_uploaded_files)$files['new']- from$_FILESResult: Validation errors like:
Root Cause: In
EntryObjectMutation::initialize_files(), the code was only skipping the multi-upload pipeline for single-file fields when$_FILESdidn't exist. However, when files are submitted via GraphQL multipart,$_FILESdoes exist, so single-file fields would still go through the multi-upload processing, causing duplicates.How
Modified
EntryObjectMutation::initialize_files()to always skip multi-upload processing for single-file fields, regardless of$_FILESexistence:Before:
After:
Changes:
$_FILES(handled byFileUploadValuesInput)gform_uploaded_files(unchanged behavior)Testing Instructions
Example GraphQL mutation:
Expected Result: No "Number of files (2) exceeds limit (1)" errors for single-file fields.
Additional Info
Error before fix:
{ "data": { "submitGfForm": { "errors": [ { "id": 10, "message": "Number of files (2) exceeds limit (1)." } ] } } }After fix: Submission succeeds with correct file count.
This fix ensures proper separation between single-file and multi-file upload handling, preventing duplicate file processing when using GraphQL multipart form data.
Checklist:
This PR is tested to the best of my abilities.
This PR follows the WordPress Coding Standards.
This PR has proper inline documentation.
This PR has unit tests to verify the code works as intended.
The changes in this PR have been noted in CHANGELOG.md