Problem/Motivation
While investigating another issue (#2535422: Alternative text disappears on preview) I stumbled across this bug.
Steps to recreate:
- Go to /node/add/article
- Fill in the 'Title' field
- Hit the 'Preview' button
- Hit the 'Back to content editing' button
- Hit the 'Preview' button
- Fatal Error
Fatal error: Call to a member function getEntityTypeId() on a non-object in /var/www/site/docroot/core/modules/comment/src/CommentForm.php on line 78
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | interdiff.txt | 2.41 KB | larowlan |
| #23 | comment-preview-twice-2535792.pass_.patch | 2.76 KB | larowlan |
| #23 | comment-preview-twice-2535792.fail_.patch | 2.18 KB | larowlan |
| #22 | preview_feature_broken-2535792-22.patch | 596 bytes | biigniick |
| #15 | interdiff-2535792-6-15.txt | 1.81 KB | nlisgo |
Comments
Comment #1
nlisgo commentedComment #2
biigniick commentedi cannot reproduce this on drupal-8.0.0-beta12
Comment #3
nlisgo commentedThanks @BiigNiick I confirm also that I cannot reproduce this on drupal-8.0.0-beta12.
Comment #4
nlisgo commentedI've tracked down the commit where this bug crept in: #2498919: Node::isPublished() and Node::getOwnerId() are expensive
The last commit sha that didn't have the bug was 9907029cdb30ccc691832865658288af1cfdd25d
Comment #5
nlisgo commentedComment #6
berdirCan you adjust one of the existing tests to trigger this? Not clear to me how the other issue could have broken this, I tried to be very, very careful about keeping BC.
Comment #7
cilefen commentedThis change should go in PagePreviewTest if anyone is trying.
Comment #8
nlisgo commentedAttempting to write the test requested in #6.
Comment #9
nlisgo commentedComment #10
nlisgo commentedThe test didn't workout too well because it didn't trigger the error.
Unassigning for now.
Comment #11
nlisgo commentedWe need a test which can reproduce the problem described in this issue.
Comment #12
berdirThat error is in comment.module. So I think it won't happen unless you have comment enabled and a comment field on that node type.
This has to be the check in CommentDefaultFormatter::viewElements(). Somehow in_preview is then empty when it shouldn't be.
I'm guessing this doesn't work anymore the way we it's supposed to:
in NodeForm::form().
Try to explicitly change it to set the value to NULL and see if that makes a difference.
Also compare in_preview in the preview() method and the actual controller..
Comment #13
nlisgo commentedI will pick this up again tomorrow. Thanks for the pointers @Berdir.
Comment #14
nlisgo commented@Berdir, I should make clear that the reason I believe that the commit #2498919: Node::isPublished() and Node::getOwnerId() are expensive caused this is because after @BiggNiick determined that the bug was not present in drupal-8.0.0-beta12 I found out when the bug first appeared by trial and error (checking out at various commits and reinstalling until I could narrow down, to the exact commit, where the bug was introduced). I'm not clever enough to guess which commit might have broken it :)
I should have some time later today to implement your suggestions on triggering the error in a test only patch and see if your suggestion in #12 fixes it :) Thanks so much.
Comment #15
nlisgo commentedComment #16
nlisgo commentedI just can't seem to break it!
Comment #17
biigniick commentedI can confirm this issue is now in beta-13
this is the error i'm getting.
Fatal error: Call to a member function getEntityTypeId() on a non-object in ..../Sites/dru8/core/modules/comment/src/CommentForm.php on line 78Comment #18
biigniick commentedso, i figured i could help narrow it down by uninstalling the comment module but i'm not able to uninstall it with a fresh install... maybe related
it says
next, i did a minimal install so the comment module would not be installed and the same steps create a fatal error with this message
this would suggest the comment module is not the culprit.
- nick
Comment #19
cilefen commented@BiigNiick See #2489472: Field-based module dependency uninstall message is unhelpful and not grammatically correct.
It means there are comment fields on some content types on your install. The message is not helpful, as you have seen.
Comment #20
biigniick commentedAh, thank you @cilefen.
Comment #21
biigniick commentedso the error message is in an if statemement that shouldn't even be run
the problem is probably in the section above where the $is_in_preview is set
also, it works as expected if you use the browser back button. if you click the 'back to content editing' button something is not set right, i would think
on line 42 this must not be setting correct?
- nick
Comment #22
biigniick commentedit works if you comment this line out.
i know this is not a correct fix, but gets us closer to what's going wrong...
- nick
Comment #23
larowlanfail/pass
Comment #25
amateescu commentedLooks good :)
Comment #26
fabianx commentedRTBC + 1
Comment #27
nlisgo commentedFantastic. Marking 'Needs work' so we can prepare a beta evaluation.
Comment #28
biigniick commentedYAY! this works for me. I'm glad i could help find where the problem was ;)
the patch from #23 works as expected for me. +1 RTBC and ready for beta evaluation
Comment #29
jibranIt's a major bug so no need for beta eval we can always fix bugs.
Comment #30
nlisgo commentedThanks for the clarification @jibran.
Comment #32
webchickHa, this is timely. :) Just hit this bug a few mins ago while doing a live demo of D8. Fix looks great, as does the test.
Committed and pushed to 8.0.x. Thanks!
Comment #34
granticusiv commentedAssuming this is all good now, but noticed this error in 8.0.0-beta14; base install (no additional config or contrib modules), adding the first Article node for the site.