Skip to content

Setting catalog/seo/category_url_suffix through Admin to an empty string sets value to NULL, which fails return type declaration in code that uses the value #29442

Closed
@danemacmillan

Description

@danemacmillan

Preconditions (*)

  1. 2.3.3-p1
  2. Have products created with the Generate "category/product" URL Rewritesconfig set to Yes in Stores->Config->Catalog->SEO.
  3. Set Generate "category/product" URL Rewrites to No in Stores->Config->Catalog->SEO, which will clear a lot of rows in the url_rewrite table, but not all.
  4. Ensure there is at least one url_rewrite.request_path with a category/product URL. That will need to be visited after performing the below.

Steps to reproduce (*)

  1. Use category suffixes, like .html in the admin for catalog/seo/category_url_suffix.
  2. Save.
  3. Note that the value in core_config_data at path catalog/seo/category_url_suffix is a string: .html.
  4. Empty the value and save, effectively meaning there should be no suffix.
  5. Save.
  6. Note that the value in core_config_data at path catalog/seo/category_url_suffix is of type NULL, instead of string.
  7. Clear cache. Visit a product page that has or used to have a category path in the URL, using the long URL.

Expected result (*)

  1. Product page should load with a 404.

Actual result (*)

  1. A blank page and 500 HTTP error code loads instead.
  2. See this error instead when displaying errors:
 Fatal error: Uncaught TypeError: Return value of Magento\CatalogUrlRewrite\Model\Storage\DynamicStorage::getCategoryUrlSuffix() must be of the type string, null returned in /Users/danemacmillan/projects/linusshops/storefront233/releases/20200729133910803462/app/code/Magento/CatalogUrlRewrite/Model/Storage/DynamicStorage.php:150 
 
 Stack trace: 
 
 #0 /Users/danemacmillan/projects/linusshops/storefront233/releases/20200729133910803462/app/code/Magento/CatalogUrlRewrite/Model/Storage/DynamicStorage.php(171): Magento\CatalogUrlRewrite\Model\Storage\DynamicStorage->getCategoryUrlSuffix('5') 
 #1 /Users/danemacmillan/projects/linusshops/storefront233/releases/20200729133910803462/app/code/Magento/CatalogUrlRewrite/Model/Storage/DynamicStorage.php(102): Magento\CatalogUrlRewrite\Model\Storage\DynamicStorage->findProductRewriteByRequestPath(Array) 
 #2 /Users/danemacmillan/projects/linusshops/storefront233/releases/20200729133910803462/app/code/Magento/UrlRewrite/Model/Storage/AbstractStorage.php(66): Magento\CatalogUrlRewrite\Model\Storag in /Users/danemacmillan/projects/linusshops/storefront233/releases/20200729133910803462/app/code/Magento/CatalogUrlRewrite/Model/Storage/DynamicStorage.php on line 150

The reason this happens is due to the declared return type, which only expects and allows string, while saving that configuration through the admin to an empty value will actually set NULL instead of just an empty string. Regardless of one's ability to reproduce this issue, it is a clear, logical problem.

The offending code and commit, which just randomly declared return types by @slopukhov:

f70f1b2#diff-eb1d8c6c0059c0e71a5cbdc544a4558fR144

Insight: simply because return types can be declared does not mean that they should be declared. It is not as benign a change as perceived.

Workaround

Manually go to the catalog/seo/category_url_suffix config in the DB and ensure that it contains an empty string instead of NULL. Clear the cache, and suddenly those pages will load.


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Labels

Issue: Format is validGate 1 Passed. Automatic verification of issue format passedProgress: doneReported on 2.3.3-p1Indicates original Magento version for the Issue report.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions