Summary updated until comment #101.
(The following happens in D7. The comment module in D8 has no problems, according to #99 and #101.)
After changing the comment_body field of a content type, the following warnings appear:
1. after deleting the comment_body field: when opening admin/content/comment I get this error:
Notice: Undefined property: stdClass::$comment_body in comment_admin_overview() (line 108 of /modules/comment/comment.admin.inc).
2. after deleting the comment_body field: when commenting on a node of that type:
Notice: Undefined property: stdClass::$comment_body in comment_submit() (line 2183 of /modules/comment/comment.module).
3. after making the comment_body field not-required: when commenting on a node with an empty body field:
Notice: Undefined offset: 0 in comment_submit() (line 2197 of /modules/comment/comment.module)
4. after setting the filter of the comment body to plain text, and clicking on the preview button to show the preview of a comment:
Notice: Undefined index: format in comment_preview() (line 2071 of /modules/comment/comment.module) (from #2077901)
The comments get submitted without problems but i don't know what's the error about.
Comment | File | Size | Author |
---|---|---|---|
#129 | interdiff-1038652-120-128.txt | 2.22 KB | jacob.embree |
#128 | 1038652-128.patch | 5.47 KB | dcam |
#84 | 1038652-comment-body-field-84-tests-only-D7.patch | 1.83 KB | johnv |
#84 | 1038652-comment-body-field-84-tests-and-fix-D7.patch | 3.75 KB | johnv |
#68 | 1038652-no-comment-body-field-68-tests-and-fix-D7.patch | 2.87 KB | Boobaa |
Comments
Comment #1
droplet CreditAttribution: droplet commentedit has some hard coding
related: #813052: Undefined index: format in comment_preview line 2065 and line 2183
Comment #2
rogical CreditAttribution: rogical commentednot the same issue, I'm using 7.7, and also get the this issue after commet_body was deleted(the reason I deleted was it can't be retrieved by views, while fields can.):
Notice: Undefined property: stdClass::$comment_body 在 comment_submit() (行 2164 在 /opt/difang/prod/qlkaixin/modules/comment/comment.module).
Comment #3
Jānis Bebrītis CreditAttribution: Jānis Bebrītis commentedfix for rogical
I hope it helps ;)
Comment #4
rogical CreditAttribution: rogical commentedthanks, but it deleted all comment contents and more or less effect the core I think.
I mean my site is already on production.
Comment #5
catchFixing issue metadata, it's wrong for these functions to assume the comment body exists. Should be an easy fix so tagging as 'novice'.
Comment #6
catchBack to normal, this is annoying but requires comments with no body which is relatively unusual.
Comment #7
rogical CreditAttribution: rogical commentedwould be usual when D7 users begin to be familar with comment entity.
and unfortunately views can't retrieve the default comment body, another body filed is needed.
Comment #8
servantleader CreditAttribution: servantleader commented+1
Working on a Drupal distribution that will have body field removed by default.
Comment #9
rogical CreditAttribution: rogical commentedOne more, the comment title would auto retrieve data from default comment body if the title is not filled.
This should be fixed if comment body is deleted. And as the comment body is designed to be deleteable, so this should be fixed.
Comment #10
droplet CreditAttribution: droplet commentednot tested yet but make sense to me.
Comment #11
rogical CreditAttribution: rogical commentedyour patch is not for this issue, comment_body should not be hardcoded anymore as comment body may be removed.
Comment #12
droplet CreditAttribution: droplet commented@rogical
oh. do you meant we should use another field instead ? so if there have 2 fields, how to handle it ? Node hasn't this implement too.
Comment #13
rogical CreditAttribution: rogical commentedthere are 2 points:
1. the comment_body filed is deleteable, so there should no other errors if user delete it.
2. views can't retrieve comment_body, but OK to other fields(long text, text etc.), so if user want to use views to retrieve comment body, how to do that? The only solution is delete the default comment_body and create a long text field.
Comment #14
droplet CreditAttribution: droplet commented1. solved in patch
2. views problem, not a core issue.
back to review.
Comment #15
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedSubscribe.
@droplet: Please explain. If you are using
$comment->comment_body
without a check, how would that fix the issue?Edit: As for the Views thing, I think you can display the comment body now.
Comment #16
rogical CreditAttribution: rogical commentedsame question, as $comment->comment_body should be have deleted.
Comment #17
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedI created a testcase to verify this bug; consider reviewing it and including it into your patches.
The secound patch is the test case + #10, though the patch is probably not the right one - just in case I missed something.
Setting to needs review to let the testbots have a go at it.
This won't be easy to fix properly, however. The point in #12 is right. We can't determine a good automatic title in all cases. Maybe we can in some?
Comment #19
droplet CreditAttribution: droplet commentedOh. my patch should not copy the $var again & the other errors show on #17 is easy to get rid of it.
Instead fix it, it can be totally remove comment body, not sure if committer like it.
If removed, we cannot backport to D7? Contri Modules are think it always exist there.
Patch attached gives someone who want to get rid of the error. I stay the issue status as need work for more discuss :)
Comment #20
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedMy patch in #17 contained a random
*/
, so the results didn't say a thing. However FAIL / FAIL was expected.Corrected that. Now lets see how the testcase does on it's own. Hopefully it fails because of Notice: Undefined property: stdClass::$comment_body in comment_submit() (line 2183 of /home/user/public_html/drupal7/modules/comment/comment.module)..
And lets see how it does with your fix. So setting to needs review.
Reviewing your patch: It looks good.
One thing: Maybe leave
out of the isset block?
Edit:
As for the Drupal 7 backport, I think we should do it. If the user deletes the body field, there should be no core errors. And of course no errors in Contrib as well, but we're not making it worse by fixing it in core.
Comment #21
droplet CreditAttribution: droplet commented@#20,
"out of the isset block?"
Your right, thanks.
Comment #22
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedDid that, another round of testing.
Comment #23
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedGreat. RTBC.
Full disclosure: I wrote the testcase that verifies this bug and is part of the patch.
Comment #24
klausidon't RTBC your own patches ;-)
Comment #25
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedOk, thanks klausi. Wasn't sure since it wasn't my fix.
Comment #26
dixon_To me, the tests on this
We don't usually use abbreviations in variable names (
$comment_attr_title
).We don't assert anything here. Shouldn't we at least look for the new comment on the page?
26 days to next Drupal core point release.
Comment #27
dixon_Also, I'm not sure how this related to this bug report? Can you explain? I looks like a reasonable thing to do, but I think that should go in another issue.
26 days to next Drupal core point release.
Comment #28
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedThank you for reviewing. I'll reroll the patch soon.
As for #27: Have a look at the hunk before that. A trim is removed there.
Comment #29
dixon_Here is a re-roll that also improves the tests by checking the administration overview page too.
I can confirm that the tests fail without the fix (due to the generated warnings), and the tests pass locally with the fix implemented. So all looks good to me.
Comment #30
dixon_I'll post a separate issue about thetrim()
in #27, since that's not related to what we are trying to fix here. We should keep fixes separate.Comment #31
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedThank you for rerolling.
I am a bit confused.
This line
$comment->subject = truncate_utf8(
trim
(decode_entities(strip_tags($comment_text))), 29, TRUE);
is moved into an if block. So isn't the missing trim a regression introduced by this fix?
Comment #32
dixon_I see! *stupid me*
Here is a new patch that correctly includes the trim we need if no comment_body exists (no new issue opened).
Comment #33
Patricia_W CreditAttribution: Patricia_W commentedWhere is the comment_body defined. I just tried to enter a new comment for a page and I got this error. I accidentally deleted the body on the page but restored it. Did that also delete the comment_body and if so how do I restore it?
Comment #34
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedCurrently there is no way to restore the comment_body field in the UI in case it got deleted, as all custom fields are prefixed with
field_
(except creating a new content type).The patch here solves the warnings, but comment_body is still the hardcoded fieldname. I am not sure what we could do about that.
Comment #35
Patricia_W CreditAttribution: Patricia_W commentedActually there is a way to restore it ... add an EXISTING field ... not add a new field.
Comment #36
rogical CreditAttribution: rogical commentedcomment_body is not an existing field, as it's designed to be deleteable, so it should be able to be deleted!
I just the one want to delete the comment_body in my site, and use specified fields instead.
Comment #37
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedOh, I wasn't aware of that. Apperently it works only if you have got at least one other content type where it exists - at least "on my machine". Maybe special fields like this one should always be in the "add existing fields" selectbox?
Then for now the workaround would be:
- Create a random content type
- Restore the comment_body field, because it's existing now
- Delete the random content type
Edit:
@rogical: Yes, but there is hardcoded behaviour that makes the field special. And one more thing is special: The name. That means (unless you use the crazy workaround) you can not restore that field, which again is special, because you can "restore" any other field. I'd love to make the comment_body field not special in any way - but that isn't a trivial problem.
If that problem isn't solved, there should at least be a way, to undo the deletion, if you need that special field for special behaviour.
Edit 2:
Maybe we could actually render the comment to get a few characters for the subject?
Edit 3:
Weren't there attempts to make the title field a normal field, too?
Comment #38
Patricia_W CreditAttribution: Patricia_W commentedI was able to add the comment body field back to the comment fields and it is working without any error messages. Since the comment_body is a special field it is part of the core and can't be deleted (AFAIK) so adding it back is not a problem.
Comment #39
Niklas Fiekas CreditAttribution: Niklas Fiekas commented@Patricia_W: Please try this:
- Make sure you have only one content type.
- Delete the comment_body field.
- Try adding it back - that shouldn't be possible.
Comment #40
Patricia_W CreditAttribution: Patricia_W commentedI hope you aren't serious about having only one content type. Do you mean I should remove all my content types? I do not intend to destroy my site.
Comment #41
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedAssuming you were on a testing/development site I was indeed serious ;) Luckily you didn't do that on production. Otherwise I would have felt guilty for not warning you.
So: It's good that this problem doesn't exists if you have content types where the comment_body field is still attached, but there is this edge case, where you can't add it back like that.
Comment #42
Patricia_W CreditAttribution: Patricia_W commentedAs I said ... I did add it back like that. I had also deleted the body field from the same content type while I was migrating to D7 and didn't know better, and I may have deleted the comment body at the same time. I had restored the body field by adding an existing field but had not noticed that that the comment_body was also missing until I tried to add a comment.
What do you mean by "edge case"?
What would cause the comment_body field not to be attached? Isn't it just part of the core fields?
Comment #43
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedThat edge case is, again: There is no other content type that has a comment_body field. To reproduce that you would have to delete the content types or comment_body fields of your existing content types (Please don't do that on your production site). It is added by core code, but you can delete
itfield instances just like instances of any other field.Comment #44
Patricia_W CreditAttribution: Patricia_W commentedThanks for the clarification. I did not read the fine print.
Comment #45
dixon_#32: 1038652-no-comment-body-field-2.patch queued for re-testing.
Comment #47
Chi CreditAttribution: Chi commentedThis error message also apears on comment preview page. It seems not so easy to fix, because it has a lot of hard coding.
Here seach results for "comment_body".
Comment #48
wayne57 CreditAttribution: wayne57 commentedThis is quite a confusing thread.
is there a way to fix the problem of getting:
Notice: Undefined property: stdClass::$comment_body in comment_submit() (line 2180 ...
in both the node when adding a comment and also in the admin comment page??
Comment #49
Niklas Fiekas CreditAttribution: Niklas Fiekas commented@wayne57: Yes, applying the patch in #29 should be a quick fix until this is polished enough to get in.
Admittedly I had forgotten about this issue. It shouldn't be too hard to get this fixed.
Comment #50
wayne57 CreditAttribution: wayne57 commentedI am getting this in D7, will this work in D7 as well?
Comment #51
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedYes. For this issue, however, we will have to do D8 first. Tagging novice to reroll the patch with LANGUAGE_NOT_SPECIFIED instead of LANGUAGE_NONE.
Comment #52
dcam CreditAttribution: dcam commentedThis reroll was a little complex due to all the changes that have occurred since last September. Hopefully I got it worked out correctly. We'll see what Testbot thinks.
The changes from LANGUAGE_NONE to LANGUAGE_NOT_SPECIFIED had already been made. I just had to roll them into the patch.
Comment #53
dcam CreditAttribution: dcam commentedOops, setting status.
Comment #55
dcam CreditAttribution: dcam commented#52 failed because CommentFormController::actions() tries to set the action elements' #weight based on #form['comment_body']['#weight'] without checking to see if it is set first.
I added the check and set the action elements' #weight = 100 by default if the body element doesn't exist. This doesn't seem like the best approach to me. I'm interested to know if anyone has a better suggestion.
Comment #56
ryan.gibson CreditAttribution: ryan.gibson commentedI tested the functionality of the patch from #55. Verified that the error existed before the patch and that after cleanly applying the patch the error no longer appeared. Code review looks okay as well.
I guess this could use some more input on dcam's comments about setting a default #weight so I'm not going to change status atm.
Comment #57
dcam CreditAttribution: dcam commented#55: comment-1038652-55.patch queued for re-testing.
Comment #58
Devin Carlson CreditAttribution: Devin Carlson commentedMarked #1371682: Undefined index: format in comment_preview line 2053 as a duplicate.
Comment #59
dagmarI'm pretty sure that this is not correct.
Comment #60
Niklas Fiekas CreditAttribution: Niklas Fiekas commented@dagmar: Yeah ... here's a reroll.
Comment #61
tds2012 CreditAttribution: tds2012 commentedHi
I'm kind of new, but I have the same issue here, instead of body_comment I use an image and I get the same error. Now, that patch sounds interesting but where do I apply it and how?
Thanks!
Tommy
Comment #62
dcam CreditAttribution: dcam commented#60: 1038652-no-comment-body-field-60.patch queued for re-testing.
Comment #64
rootworkI tried to reroll the patch, but it's clear a bunch of stuff has changed in the functions this patch affects. So I've removed the novice tag.
Comment #65
BoobaaRerolled the patch found in #60 against latest drupal-8.x in git; attaching both with and without actual fix to have a red and a green response from testbot. (However, it looks like the asserts mentioned in #26 have not been addressed yet; though the test result does show yellow exceptions. Hope that's enough for testbot to fail, too.)
Comment #67
Boobaa#65: 1038652-no-comment-body-field-65-tests-and-fix.patch queued for re-testing.
Comment #68
BoobaaHere is the fix for D7; tests are clean backport from D8 patch, fixes are mine (as I found no usable fix from the previous comments).
Comment #70
Boobaa#68: 1038652-no-comment-body-field-68-tests-and-fix-D7.patch queued for re-testing.
Comment #71
BoobaaOh, forgot to remove the tag.
Comment #72
dcam CreditAttribution: dcam commentedSetting the issue back to 8.x. The status is still Needs Review for the 8.x patch in #65.
Comment #73
errev CreditAttribution: errev commentedI got this error trying to patch on D7.
$ git apply -v 1038652-no-comment-body-field-68-tests-and-fix-D7.patch
Checking patch modules/comment/comment.module...
error: modules/comment/comment.module: No such file or directory
Checking patch modules/comment/comment.test...
error: modules/comment/comment.test: No such file or directory
Comment #74
BoobaaRerolled #65 for latest 8.x.
Comment #75
dimaro CreditAttribution: dimaro commented74: 1038652-no-comment-body-field-74-tests-and-fix.patch queued for re-testing.
Comment #77
BerdirInstead of using isset()/empty, you could use $comment->hasField('comment_body').
Note that this will return TRUE for an empty field (I don't think that's actually allowed), unlike !empty().
Comment #78
BoobaaRerolled #74 against latest 8.x, following Berdir's advice from #77.
Comment #80
johnvThis issue/patch also resolves the problem of #2045409: Notice: Undefined offset: 0 in comment_submit() (line 2197 of comment/comment.module) :
I made it a duplicate of this issue.
But it then needs an extra testNotRequiredCommentBody()..
Comment #81
johnvI applied #68 on 7.x successfully.
@errev (#74) : you could not apply the patch. It seems you started from the wrong directory.
Comment #82
johnvAttached is a new D7-version of #68. It still lacks the extra testNotRequiredCommentBody() test.
Comment #83
dcam CreditAttribution: dcam commentedSending this back to 8.x.
Comment #84
johnvSorry to bother, attached D7-patches with tests.
Comment #85
johnvThe D8-patches from #78 are not valid anymore. Attached a new try.
- The fix contents did not need changing for 'not required comment_body'
- The test now contains an extra test for the new use case.
Comment #86
johnvNot sure how to trigger the testbot for D8-patch.
[EDIT] Oh, seems something is happening...
Comment #89
johnvComment #90
johnvComment #95
johnvOK, I learned how to run tests on my local machine, and how to write proper tests.
Attached D7-patches have better tests.
next stop: a fresh attack on D8.
Comment #97
johnvComment #98
uwe_a CreditAttribution: uwe_a commentedGreetings, So do we wait for backport or do we keep tracking d7 issue (https://www.drupal.org/node/2077901 for example) ?
Comment #99
larowlanNot a problem in D8
Comment #100
wOOge CreditAttribution: wOOge commentedUntil there is a working patch for D7 and it's committed, I did the following to "solve" the problem:
comment_body
by using the "Add existing field" optioncomment_body
field requiredcomment_body
settings so that even if required, the user would not have to enter data into itcomment_body
field using Filed Permissions (https://www.drupal.org/project/field_permissions) ModuleComment #101
johnvIndeed, the D8-version is very different, and has no problems.
I Added the symptoms of #2077901: Comment Preview Error for Plain Text (Undefined index: format in comment_preview()) to the summary.
@uwe_a, @wOOge, the best way to get this issue committed is to test the latest patch, confirm it works and set it to RTBC after 2 positive confirmations.
Comment #105
rodrigoaguileraManual testing on 7.x:
without the patch there is notices and with the patch the notices are gone
Reviewed also the code and looks ok.
Comment #107
sun-fire CreditAttribution: sun-fire commented#100 solve problem for me. Thanks!
Comment #109
David_Rothstein CreditAttribution: David_Rothstein commentedLooks like a testbot fluke.
Comment #112
David_Rothstein CreditAttribution: David_Rothstein commentedTestbot fluke.
Comment #115
David_Rothstein CreditAttribution: David_Rothstein commentedTestbot fluke.
Comment #118
dcam CreditAttribution: dcam commentedComment #119
David_Rothstein CreditAttribution: David_Rothstein commentedI would like to get this in but there are a few issues here, mostly small things but not entirely.
Since we're no longer guaranteeing that $comment->subject will be trimmed, don't we have to do
if (trim($comment->subject) == '') {
at the bottom instead?Otherwise I think we're introducing a bug where the comment subject could wind up empty in the end, rather than saying "No subject".
Why do these test functions take a parameter? There is no code that will ever pass it in...
The function summary should fit on one line, 80 characters or less.
Here and elsewhere, there are a lot of spacing issues (for example there should be spaces after "elseif" and before the "{" (see https://www.drupal.org/coding-standards#controlstruct).
Comment #120
xenophyle CreditAttribution: xenophyle commentedPatch trying to address concerns in comment #119.
Comment #121
geekygnr CreditAttribution: geekygnr at GiantGoat Web Development Inc. commentedI patched with #120 and the notices went away.
Comment #122
johnvComment #124
David_Rothstein CreditAttribution: David_Rothstein commentedComment #125
nickonom CreditAttribution: nickonom commentedI do confirm the patch in #120 is applied cleanly on PHP 7.0.8 and addresses the issue.
Comment #126
jacob.embree CreditAttribution: jacob.embree at St. Louis Integration commented+ } // Attach the user and time information.
The comment should be on its own line, separate from the closing brace.
There are a bunch of trailing spaces.
Comment #127
nickonom CreditAttribution: nickonom commentedWith PHP 7.1.7 the last patch is giving:
Comment #128
dcam CreditAttribution: dcam commentedFixed the issues mentioned in #126 and #127.
Comment #129
jacob.embree CreditAttribution: jacob.embree at St. Louis Integration commented#120 fixes the issues mentioned by David_Rothstein in #119. #128 is the same but without the whitespace errors.
Comment #130
silverham CreditAttribution: silverham at EY Digital commented#128 fixes the notice error for me too. Patch applies cleanly.
Comment #131
mandreato CreditAttribution: mandreato commented#128 does work for me too.
Comment #132
nickonom CreditAttribution: nickonom commentedI wonder will this ever be applied?
Comment #133
yuraosn CreditAttribution: yuraosn as a volunteer and commentedThe problem is urgent for v: 7.59
Comment #135
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedUnfortunatelly the patch #128 fails the core tests now. This needs work.