Skip to content

Read a non-attribute-set column as an empty attribute set - #2688

Open
kha333n wants to merge 1 commit into
lunarphp:1.xfrom
kha333n:fix/attribute-data-unreadable-rows
Open

Read a non-attribute-set column as an empty attribute set#2688
kha333n wants to merge 1 commit into
lunarphp:1.xfrom
kha333n:fix/attribute-data-unreadable-rows

Conversation

@kha333n

@kha333n kha333n commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #2687.

1.x only — 2.x already guards this, so no forward port.

A product whose attribute_data holds anything other than an attribute set
cannot be loaded: Product::find() throws, and so does every listing whose range
includes it.

The fix

get() decoded the column and iterated the result without checking it was
iterable. It now reads anything that is not an array as an empty attribute set,
which is what 2.x does.

is_array() rather than 2.x's ?: []: both catch null and 0, which are
the values that actually arise, and is_array() also catches a truthy scalar
that would otherwise reach the same foreach.

Rows reach this state through Lunar itself — a non-UTF-8 attribute value makes
set() store 0 (#2685), and 0 is one of the values get() cannot read.
Fixing that stops new ones, but the records already damaged stay unreadable, and
cannot be repaired through Lunar because Lunar cannot read them.

Touches the same file as #2686, which fixes the write side. No overlap in intent,
but whichever lands second wants a rebase.

Tests

tests/core/Unit/Base/Casts/AsAttributeDataReadTest.php:

  • can load a record whose attribute data is not an attribute set — a dataset
    over the five shapes the column can hold: null, 0, "abc", 123 and
    malformed JSON. All five throw on 1.x.
  • can still load attribute data that is an attribute set — passes before and
    after, and is the guard that the fix skips only non-attribute-sets.

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

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

A product whose attribute_data is JSON null cannot be loaded at all

1 participant