Fix TypeError when the type param is missing on the admin new product page - #318
Merged
rhoerr merged 1 commit intoAug 11, 2026
Merged
Conversation
Magento\Catalog\Controller\Adminhtml\Product\NewAction::execute() passes the raw 'type' request param straight into Magento\Framework\RegexValidator::validateParamRegex(), which is typed as string. Opening admin/catalog/product/new without a type param makes getParam() return null and the request dies with a TypeError instead of forwarding to noroute. An array param (?type[]=simple) fails the same way. Guard the call like Sales\Controller\Adminhtml\Order\Create\LoadBlock already does, and forward to noroute for any non-string type.
Open
5 tasks
4 tasks
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.
Description
Opening the admin "New Product" page without a
typerequest parameter throws a fatalTypeErrorinstead of forwarding tonoroute:NewAction::execute()passes the raw request param straight intoRegexValidator::validateParamRegex(), which is declared asstring $params.RequestInterface::getParam()returnsnullwhen the parameter is absent, so the request dies with a 500. The same happens for an array param (?type[]=simple), which producesarray given.Magento\Sales\Controller\Adminhtml\Order\Create\LoadBlockalready guards its call to the same method;NewActiondoes not.Fixed Issues
Fixes the fatal error above. No linked GitHub issue.
Manual testing scenarios
admin/catalog/product/new/(notypeand nosetin the URL).TypeErrorinexception.log.noroutepage.admin/catalog/product/new/?type[]=simple.TypeError ... array given.noroutepage.admin/catalog/product/new/set/4/type/simple/URL and confirm the new product form still loads.typeparam containing layout-handle injection characters still forwards tonoroute.Questions or comments
The alternative fix would be widening
RegexValidator::validateParamRegex()to accept?string. That changes a public method signature on a non-final framework class, so I kept the change in the caller instead, matching the existingLoadBlockpattern.Contribution checklist
Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\NewActionTest::testExecuteWithoutTypeParamand::testExecuteWithNonStringTypeParam, both fail with the reportedTypeErrorwithout the fix)vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php)Related Pull Requests
The same fix submitted upstream to Magento: magento/magento2#41105