Numeric product slugs abort artifact composition (hash() given int)

Open Beginner friendly
#4,836 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
79/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend, testing

Research direction

Start in ArtifactCompiler::runtimeDeclarationsFromFallbacks() around line 1533 and trace how product slugs become keys in $products. Check the other slug or route keyed maps in that function for the same integer key coercion, then add a regression fixture with a numeric product slug such as 249. Done means composition succeeds and the product entity ID hashes the slug string.

Written by the indexing model from the issue text.

Description

bug

Summary

Artifact composition aborts with TypeError: hash(): Argument #2 ($data) must be of type string, int given when a captured product has a numeric slug.

ArtifactCompiler::runtimeDeclarationsFromFallbacks() keys $products by product slug. PHP stores a numeric-string key such as "199" as an int, so the later loop

foreach ($products as $productSlug => &$product) {
    $product['id'] = 'product:' . hash('sha256', $productSlug);

passes an int to hash() under strict_types=1 and the whole import fails in the compose phase (static_site_importer_direct_artifact_phase_failed). Same class as #3098.

Evidence

Square Online store whose product URLs end in numeric IDs (/product/<name>/249, /263, /264). Every one of 46 pages compiled; compose failed:

ArtifactCompiler.php:1533
#0 ArtifactCompiler.php(1533): hash('sha256', 199)
#1 ArtifactCompiler.php(478): ArtifactCompiler->runtimeDeclarationsFromFallbacks(Array, Array, 'website/index.h...', ...)
#2 StagedTransport.php(522): ArtifactCompiler->finalizeArtifact(...)
#3 StagedTransport.php(423): ArtifactCompiler->composeWithCssRuleTrees(...)

Reproduced with Static Site Importer 1.33.392 / php-transformer 0.45.264; the same lines are on trunk (v0.45.270). This matches a production import that failed during building on the same source.

Expected

A product whose slug is all digits composes like any other product; its entity id is product: + sha256 of the slug string.

Suggested fix

Treat slug keys as strings where they are read back (e.g. hash('sha256', (string) $productSlug)), and audit the other slug/route-keyed maps in the same function for the same int-key coercion. Regression fixture: a product grid fallback with one product whose slug is numeric (e.g. 249); compose succeeds and the product entity id is the hash of "249".


Filed by Claude (Anthropic) via Claude Code during the Data Liberation import loop; the stack trace was captured from a local reproduction.

Dominant language
PHP
Stars
25
Forks
3
Avg merge
2h 29m
Merged PRs (30d)
931

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Automattic/blocks-engine

All issues in Automattic/blocks-engine

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.