node_save() doesn't set $node->comment

Wesley Tanaka - December 9, 2005 - 17:30
Project:Drupal
Version:x.y.z
Component:node.module
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

going through my set of patches off of drupal cvs that i needed to make to get things working.

AttachmentSizeStatusTest resultOperations
set_node_comment.patch445 bytesIgnoredNoneNone

#1

Wesley Tanaka - December 9, 2005 - 17:31

by the way, i think the idea here: http://drupal.org/node/40256

would cause these kinds of problems to be flushed out very quickly.

#2

Wesley Tanaka - December 13, 2005 - 07:30

please commit me!

Also, for those searching for bugs using the search:

comment off default disabled disable new node forum topic comments ignore admin setting

#3

tachyonxv - December 13, 2005 - 11:58

This fixes the forum bug for 4.7 too. I think drupal sets comments disabled by default, so this would be better.

if (!isset($node->comment)) {
  $node->comment = variable_get("comment_$node->type", COMMENT_NODE_DISABLED);
}

#4

Morbus Iff - December 14, 2005 - 19:05

I'm confused on this one - check comment_nodeapi, 'validate'. The $node->comment is being set there, to the default READ_WRITE (which I think is the right setting, not DISABLED) - why isn't it becoming a part of the $node? Isn't validate supposed to be called before save?

#5

chx - December 14, 2005 - 19:21

in validate you can't change anything. validate validates.

#6

Morbus Iff - December 14, 2005 - 19:42
Version:x.y.z» 4.7.0-beta1

#7

Morbus Iff - December 14, 2005 - 19:45

This is the same patch as wtanaka's, but removes the useless set in comment_nodeapi, validate.

AttachmentSizeStatusTest resultOperations
_40563_comments.patch1.8 KBIgnoredNoneNone

#8

aaron - December 14, 2005 - 20:18

+1 to Morbus's patch. And definitely keep it READ_WRITE. (This also fixes http://drupal.org/node/41152 )

#9

aaron - December 14, 2005 - 20:21
Status:needs review» reviewed & tested by the community

Sorry, forgot to set the status -- this does the job (Morbus's patch)

#10

tachyonxv - December 15, 2005 - 16:02

Morbus's one looks correct...

#11

Dries - December 16, 2005 - 12:55
Status:reviewed & tested by the community» needs work

Ugly patch. Why do we set that field in node_save()? We don't do that for any of the other 'default values'?

#12

Morbus Iff - December 16, 2005 - 13:40
Status:needs work» needs review

You're right. Attached a new one.

AttachmentSizeStatusTest resultOperations
_40563_comments_0.patch1.94 KBIgnoredNoneNone

#13

Wesley Tanaka - December 17, 2005 - 11:23

I've applied http://drupal.org/files/issues/_40563_comments_0.patch

against 4.7.0-test2, and it works for me.

#14

Morbus Iff - December 17, 2005 - 15:51
Status:needs review» reviewed & tested by the community

#15

Morbus Iff - December 19, 2005 - 14:41
Version:4.7.0-beta1» 4.7.0-beta2

#16

Cvbge - December 25, 2005 - 12:22
Version:4.7.0-beta2» x.y.z

Tested, works as expected.

#17

Steven - December 31, 2005 - 18:50
Status:reviewed & tested by the community» needs work

Why are we providing a form value for a comment option in node.module? This does not make sense.

#18

Morbus Iff - December 31, 2005 - 20:44

Previously, we were doing this in comment_nodeapi 'validate' - that code still remains, actually, and is removed as part of the original patch. Chx tells me that validate no longer (or maybe, never did - I dunno) modifies the form variables, so it can't happen there. The only other place it *could* happen would be in comment_nodeapi 'insert' and 'update', right? In which case, that'd be an entirely new query, just to set the node.comment? Need direction for proper handling of this.

#19

merlinofchaos - January 4, 2006 - 23:38
Status:needs work» needs review

This is all, IMO, on the wrong track.

For one, we shouldn't be reverting to the default in any case. If an admin set it, just because a user edits it doesn't mean it should revert. And it doesn't have to.

formsapi gives us:

<?php
  $form
['user_comments']['comment'] = array(
   
'#type' => 'value',
   
'#value' => $selected,
  );
?>

AttachmentSizeStatusTest resultOperations
node-comment.patch2.79 KBIgnoredNoneNone

#20

chx - January 5, 2006 - 06:28

Merlin, you are on the right track. Let's see this version.

AttachmentSizeStatusTest resultOperations
node-comment_0.patch3.1 KBIgnoredNoneNone

#21

chx - January 5, 2006 - 06:41
Status:needs review» reviewed & tested by the community

I moved the prepare op so that patch is smaller. To my eyes, this seems correct. The prepare bit happens when the node is new, otherwise node_load loads $node->comment. The form part is correct: admins can change this, users are not presented with this change but in place there is a value typed field (which is immutable) with same value.

AttachmentSizeStatusTest resultOperations
node-comment_1.patch2.63 KBIgnoredNoneNone

#22

UncleD - January 5, 2006 - 06:55

I thoroughly tested this patch, creating different users (non admin) before and after applying the patch. Before applying it, SELECT comment from node where nid=NODE# returned 0, and on the site, no comments being added was possible. After applying, nid=NODE# returned 2, and commenting was possible.

#23

UncleD - January 5, 2006 - 07:03

Tested http://drupal.org/files/issues/node-comment_1.patch just posted by chx. Works perfect. +1

#24

Wesley Tanaka - January 5, 2006 - 13:45

What happens if an unprivileged user POSTS data on their own?

#25

chx - January 5, 2006 - 13:47

Nothing. When the form is built, the node->comment gets a value and that won't be overwritten in form builder.

#26

Dries - January 5, 2006 - 14:36
Status:reviewed & tested by the community» fixed

Committed to HEAD. Thanks.

#27

Anonymous - January 19, 2006 - 14:40
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.