Skip to content

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Nov 20, 2023

Description:

Steps to reproduce the original issue:

  • Create a custom dimension (if there isn't any yet)
  • Create a segment for that custom dimension (for current site only)
  • Open the segment selector and choose any segment for comparison
  • Reports will fail to load with the error "Call to a member function getSqlSegment() on null in /srv/matomo/core/Segment.php:407"

fixes #21573

Review

@sgiehl sgiehl added this to the 5.0.0 milestone Nov 20, 2023
@sgiehl sgiehl force-pushed the m21573 branch 2 times, most recently from a315200 to 7ec0feb Compare November 20, 2023 14:13
@sgiehl sgiehl requested a review from a team November 20, 2023 14:15
@sgiehl sgiehl added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Needs Review PRs that need a code review labels Nov 20, 2023
@sgiehl sgiehl marked this pull request as ready for review November 20, 2023 14:15
Copy link
Contributor

@michalkleiner michalkleiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look sensible to me though I haven't run it locally to verify it's broken without the change and this change fixes it.

My only concern would be using ?? to fall back to idsite from the request without any following check what the idsite actually is and directly using it.

@sgiehl
Copy link
Member Author

sgiehl commented Nov 21, 2023

You mean this line:

$idSite = $modifiedParams['idSite'] ?? $this->request->getStringParameter('idSite');

Well, currently $modifiedParams['idSite'] will actually never be set, as we currently don't allow to compare different sites. If we ever plan to, this would be prepared here 🙈
And $this->request->getStringParameter('idSite') will throw an exception at this point if idSite isn't set in the request. As this was also done the same way in other places in that file, that shouldn't cause additional trouble. And if idSite would be set to an invalid value in the request, Matomo would throw an error long before it gets to this part of the code.

Copy link
Member

@mneudert mneudert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does fix the described problem for me locally 👍

@sgiehl sgiehl merged commit 74ba3aa into 5.x-dev Nov 21, 2023
@sgiehl sgiehl deleted the m21573 branch November 21, 2023 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Development

Successfully merging this pull request may close these issues.

[Bug] Fatal error: Call to a member function getSqlSegment() on null in Segment.php
3 participants