Skip to content

[2.x] fix(sticky): look up the excerpt relationship on the discussions resource - #4883

Merged
imorland merged 1 commit into
2.xfrom
im/fix-sticky-excerpt-included-context
Aug 2, 2026
Merged

[2.x] fix(sticky): look up the excerpt relationship on the discussions resource#4883
imorland merged 1 commit into
2.xfrom
im/fix-sticky-excerpt-included-context

Conversation

@imorland

@imorland imorland commented Aug 2, 2026

Copy link
Copy Markdown
Member

Regression fix for #4882, found by clicking around a live install within hours of merge — a posts request for any sticky discussion 500s:

EloquentBuffer::loadAggregate(): Argument #3 ($aggregate) must be of type array, null given

Root cause

The excerpt field resolved the firstPost relationship from $context->collection — the request's primary resource. On the discussions index that's DiscussionResource and everything works (which is why #4882's tests all passed). But the posts index default-includes each post's discussion, and when a sticky discussion is serialized as an included resource, the primary resource is PostResource: the field lookup misses, EloquentBuffer::load() receives a null relationship, and its !$aggregate && $relationship branch condition sends it into loadAggregate(null) → TypeError.

The testing gap in #4882: every payload test hit /api/discussions; none exercised a discussion serialized as an included resource of another endpoint.

Fix

Look the relationship up on the discussions resource explicitly:

$resource = $context->api->getResource('discussions');

Testing

New regression test: GET /api/posts?filter[discussion]=<sticky> returns 200 with firstPostExcerpt on the included discussion — verified failing (500) against current 2.x HEAD and green with the fix. Sticky suite 27/27, PHPStan clean, and the reporting URL's document + posts API both return 200 on a live install.

Worth a thought for later (not this PR): EloquentBuffer::load() treating "no aggregate + no relationship" as an aggregate call is a footgun — a loud guard there would have turned this into an obvious error instead of a TypeError two frames deep.

…urce

The excerpt field resolved the firstPost relationship from
$context->collection — the REQUEST's primary resource. On the
discussions index that is the discussions resource and everything
works, but when a sticky discussion is serialized as an INCLUDED
resource, the primary resource is something else entirely. The posts
index default-includes each post's discussion, so any posts request
for a sticky discussion looked firstPost up on the posts resource,
found nothing, and handed the relationship buffer a null relationship —
which sends it down its aggregate path and crashes with a TypeError.

The lookup now targets the discussions resource explicitly via
$context->api->getResource(). Regression test: a posts request for a
sticky discussion returns 200 with the excerpt on the included
discussion — it fails with a 500 against the previous code.
@imorland
imorland requested a review from a team as a code owner August 2, 2026 10:24
@imorland imorland changed the title fix(sticky): look up the excerpt relationship on the discussions resource [2.x] fix(sticky): look up the excerpt relationship on the discussions resource Aug 2, 2026
@imorland imorland added this to the 2.0.0-rc.6 milestone Aug 2, 2026
@imorland
imorland merged commit 76f8eef into 2.x Aug 2, 2026
25 checks passed
@imorland
imorland deleted the im/fix-sticky-excerpt-included-context branch August 2, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant