Skip to content

[2.x] fix: guard against missing session in FlarumDataSource::getSessionData() - #43

Merged
DavideIadeluca merged 1 commit into
FriendsOfFlarum:2.xfrom
gianniguida:fix/null-session-2x
Aug 27, 2026
Merged

[2.x] fix: guard against missing session in FlarumDataSource::getSessionData()#43
DavideIadeluca merged 1 commit into
FriendsOfFlarum:2.xfrom
gianniguida:fix/null-session-2x

Conversation

@gianniguida

Copy link
Copy Markdown
Contributor

Problem

FlarumDataSource::getSessionData() assumes every profiled request carries a session attribute. Requests that never pass through StartSession — token-authenticated API requests being the common case — have no session, so $session->all() throws:

Error: Call to a member function all() on null
#0 .../src/Clockwork/FlarumDataSource.php: FoF\Clockwork\Clockwork\FlarumDataSource::getSessionData()

On a production forum with an API monitoring probe (Zabbix hitting a healthcheck endpoint with an Authorization header) this fires on every poll interval and floods error tracking. Any headless API consumer using token auth triggers the same error.

Fix

Return an empty array when the request has no session, mirroring the fact that sessions are optional on Flarum's PSR-7 requests. Also fixes method name casing (getattributegetAttribute) — functionally identical, but it defeats IDE navigation and static analysis.

Testing

Verified against a local Flarum 1.x forum (Docker) with fof/clockwork 1.1.1 (the same code path exists unchanged on 2.x) enabled and the requesting user in the admin group (so the Clockwork authenticator lets the request be profiled):

  • Before the patch: curl -H "Authorization: Token <key>" http://localhost:8000/api/discussions?page[limit]=1 (no cookies) → HTTP 500, with flarum.ERROR: Error: Call to a member function all() on null in .../fof/clockwork/src/Clockwork/FlarumDataSource.php in the forum log.
  • After the patch: same request → HTTP 200, no error logged, and the request is profiled normally — the stored Clockwork request shows "sessionData": [].

🤖 Generated with Claude Code

@gianniguida
gianniguida requested a review from a team as a code owner August 27, 2026 07:27
Requests that never pass through StartSession (e.g. token-authenticated
API requests) have no 'session' attribute, so $session->all() throws
"Call to a member function all() on null". Return an empty array when
the request has no session. Also fixes method name casing
(getattribute -> getAttribute).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@DavideIadeluca
DavideIadeluca merged commit 391e0b4 into FriendsOfFlarum:2.x Aug 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants