Skip to content

Fix TypeError when the type param is missing on the admin new product page - #41105

Open
michielgerritsen wants to merge 1 commit into
magento:2.4-developfrom
michielgerritsen:fix/new-action-null-type-param
Open

Fix TypeError when the type param is missing on the admin new product page#41105
michielgerritsen wants to merge 1 commit into
magento:2.4-developfrom
michielgerritsen:fix/new-action-null-type-param

Conversation

@michielgerritsen

@michielgerritsen michielgerritsen commented Aug 7, 2026

Copy link
Copy Markdown
Member

Description (*)

Opening the admin "New Product" page without a type request parameter throws a fatal TypeError instead of forwarding to noroute:

TypeError: Magento\Framework\RegexValidator::validateParamRegex(): Argument #1 ($params) must be of type string, null given,
called in .../Magento/Catalog/Controller/Adminhtml/Product/NewAction.php on line 71
in .../Magento/Framework/RegexValidator.php:43

NewAction::execute() passes the raw request param straight into RegexValidator::validateParamRegex(), which is declared as string $params. RequestInterface::getParam() returns null when the parameter is absent, so the request dies with a 500. The same happens for an array param (?type[]=simple), which produces array given.

Magento\Sales\Controller\Adminhtml\Order\Create\LoadBlock already guards its call to the same method; NewAction does not. This change applies the same guard and forwards to noroute for any non-string type, so the validation introduced in AC-7025 keeps working while an absent parameter no longer 500s.

Related Pull Requests

The same fix submitted to Mage-OS: mage-os/mageos-magento2#318

Fixed Issues (if relevant)

No linked GitHub issue; reported from a production exception.log.

Manual testing scenarios (*)

  1. Log into the admin panel.
  2. Visit admin/catalog/product/new/ (no type and no set in the URL).
    • Before: HTTP 500, TypeError in var/log/exception.log.
    • After: forwarded to the 404 / noroute page.
  3. Visit admin/catalog/product/new/?type[]=simple.
    • Before: HTTP 500, TypeError ... array given.
    • After: forwarded to the 404 / noroute page.
  4. Visit a regular admin/catalog/product/new/set/4/type/simple/ URL and confirm the new product form still loads.
  5. Confirm the original protection still holds: a type param containing layout-handle injection characters still forwards to noroute.

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 existing LoadBlock pattern. Happy to switch approaches if you prefer the framework-level fix.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit tests (Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\NewActionTest::testExecuteWithoutTypeParam and ::testExecuteWithNonStringTypeParam, both reproduce the reported TypeError without the fix)
  • All automated tests passed successfully (vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php)

Resolved issues:

  1. resolves [Issue] Fix TypeError when the type param is missing on the admin new product page #41109: Fix TypeError when the type param is missing on the admin new product page

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.
@m2-assistant

m2-assistant Bot commented Aug 7, 2026

Copy link
Copy Markdown

Hi @michielgerritsen. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@michielgerritsen

Copy link
Copy Markdown
Member Author

@magento run all tests

@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Aug 11, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard Aug 11, 2026
@engcom-Hotel

Copy link
Copy Markdown
Contributor

@magento create issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

[Issue] Fix TypeError when the type param is missing on the admin new product page

2 participants