Open dsevillamartin opened 6 years ago
Might be related to an optional include (due to being an extension) not previously included, but required on the detail page where it reads the existing stored object instead of retrieving a refreshed version from the api..
Initial gut reaction: always returning an array makes things easier to deal with, essentially preventing problems like these from the get-go.
Or is there some case where the difference between a relationship being empty, and it not being there is interesting or relevant?
post.likes()
returns null
to indicate that the relationship is not loaded, otherwise there would be no way to tell the difference between that and an empty relationship (which is definitely important to be able to tell).
It seems that the likes relationship on one or more of the posts isn't being loaded. Looking at the JSON you've linked to, there are some posts that are included
(rather than in the primary data
- they are probably posts which have been mentioned by the main posts) which do not contain the relationship. So there's some disconnect between what posts the API is returning in the primary data vs. what posts Flarum is trying to display on the page.
@tobscure The page works just fine when trying to reproduce the error, though. Seems like it was a rare occasion of the API returning the wrong data? It did the request twice, as I tried to load the discussion twice (going back to the discussion list before trying again). Not sure what could have caused this.
Bug Report
Current Behavior I clicked https://discuss.flarum.org/d/15120 from the discussion list and the error appeared.
Steps to Reproduce Cannot reproduce on a new session, only in the same tab without refreshing.
Expected Behavior No error
Screenshots
Environment
Possible Solution Make sure post.likes() is an array before acting on it, or default to an array somehow (doesn't look like relationships let you choose a default).
Additional Context Stack trace:
Points to the following:
Here's the output received from
/api/posts?filter%5Bdiscussion%5D=15120&page%5Bnear%5D=35
, though I doubt it will be useful at all: https://paste.redevs.org/paste/4