-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[Issue] TypeError in Creditmemo\Validation\QuantityValidator caused by min() with string quantity #40302
Copy link
Copy link
Open
Labels
Area: APIsComponent: ApiUse with concrete module component label E.g. "Component: Api" + "Catalog"Use with concrete module component label E.g. "Component: Api" + "Catalog"Issue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.A defect with this priority could have functionality issues which are not to expectations.Progress: PR CreatedIndicates that Pull Request has been created to fix issueIndicates that Pull Request has been created to fix issueReported on 2.4.8-p3Indicates original Magento version for the Issue report.Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchThe issue has been reproduced on latest 2.4-develop branch
Metadata
Metadata
Assignees
Labels
Area: APIsComponent: ApiUse with concrete module component label E.g. "Component: Api" + "Catalog"Use with concrete module component label E.g. "Component: Api" + "Catalog"Issue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.A defect with this priority could have functionality issues which are not to expectations.Progress: PR CreatedIndicates that Pull Request has been created to fix issueIndicates that Pull Request has been created to fix issueReported on 2.4.8-p3Indicates original Magento version for the Issue report.Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchThe issue has been reproduced on latest 2.4-develop branch
Type
Projects
Status
Ready for Development
Preconditions and environment
Preconditions
Technical Details
Magento\Sales\Model\Order\Creditmemo\Validation\QuantityValidator::isValidDecimalRefundQty() (and related logic) relies on
min()while the function signature requires a strict float type. PHP’smin()is sensitive to both argument order and type juggling:With PHP 8.4 and strict typing, this is no longer just “unpredictable” logically, it can result in a hard TypeError when one of the values is a string but the parameter type is declared as float.
We also noticed that installing extensions like Blackfire can change how the quantity is parsed (e.g. the same value is now returned as a float instead of a string), which hides the bug because the types happen to align again.
Proposed Solution
Remove or avoid the direct use of
min()when the method signature requires strict float arguments.Ensure all quantities are explicitly cast to float (or properly validated and converted) before passing them to
isValidDecimalRefundQty()and/or before callingmin().Alternatively, replace
min()usage with explicit numeric comparison logic that operates on well-typed float values, e.g.:This keeps the method signature correct and avoids unexpected type juggling from
min()with mixed string/float inputs.Steps to reproduce
Expected result
The quantity is correctly validated and the credit memo is created or a proper validation error is returned.
Actual result
A TypeError is thrown:
TypeError: Magento\Sales\Model\Order\Creditmemo\Validation\QuantityValidator::isValidDecimalRefundQty(): Argument #2 ($itemQty) must be of type float, string given, called in vendor/magento/module-sales/Model/Order/Creditmemo/Validation/QuantityValidator.php on line 136 and defined in vendor/magento/module-sales/Model/Order/Creditmemo/Validation/QuantityValidator.php:107The root cause is that the code uses
min()with values that are not guaranteed to be float, even though the method signature for$itemQtyis float. When a string quantity is passed in, PHP 8.4’s behavior plus strict typing leads to the TypeError.Additional information
With certain extensions installed (e.g. Blackfire), the behavior of the quantity parsing changes and the value becomes a float instead of a string, so the error does not occur. This makes the problem harder to spot.
Release note
No response
Triage and priority