nodeapi update/insert cause node_save to be called twice

chuckdeal97 - March 18, 2009 - 20:20
Project:Inline
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

I've been tracking to weird errors on my site, one involving the image module (#406286: Inline module causing Image to remove uploaded image ) and the other the upload module. The nodeapi calls inline_alter_macros when op == update or insert. This, in turn, kicks off node_save again BEFORE the first node_save has finished. It does look like the node itself finishes saving, but it appears that some modules can be called more than once during this time. Possibly bad is the fact that these module could get called twice with different modes.

For instance saving an image, the image is processed first with op == insert calling image_insert, then via nodeapi the inline module kicks off node_save again, but this time op == update and image_update is called. The problem is that image wasn't designed for that and the new_file flag isn't being cleared and the second call actually deletes the newly added file!

Upload module is having a similar problem, but in its case the file is reported as being a duplicate when it is first added, but is ok on subsequent saves.

It seems to me that inline_alter_macros wants to get called before other modules, but since it can't guarantee that it will, it just calls node_save again to make sure that all of the other modules process the node again but with inline_alter_macros changes in place. Is this correct? Why not use module weighting to put the inline module as the first module?

I guess my point is that because of this "weirdness" with the save routine some modules are being called twice and their state is such that it is causing damage.

#1

chuckdeal97 - March 18, 2009 - 20:48

As a followup, I was able to get around the Image module's problem by clearing the new_file state after the file was inserted, but I can't do the same thing for Upload because there are two possible paths that lead to the problem and only one of them is state that could be cleared after the first operation. I am going to try the fix posted at http://drupal.org/node/363454.

These are only two modules that are known to suffer because of inline, I wonder if there are any others?

#2

Bryan76 - April 16, 2009 - 17:56

I agree with chuckdeal97. inline is somehow causing upload_save to be called twice in the upload module. I have verified this by adding watchdog debugging in the upload module. I tried inserting some watchdog into the inline module, but I can't find where or how it is calling upload_save twice.

#3

Bryan76 - April 16, 2009 - 18:10

Found another module that this causes a problem for. Upload Path (http://drupal.org/project/uploadpath). when trying to move an uploaded file to a specific path, it tries to move it twice, and will display an error for the second move. (because the source file is no longer in the original location).

#4

Bryan76 - April 16, 2009 - 19:07

Aha!

Here's the problem, and it's even conveniently documented.

inline.module line 236 & 237.

  // Save the node (again).
  node_save($node);

So it's pretty apparent that this "double save" is by design. However it appears to be having unintended consequences.

#5

sun - April 18, 2009 - 03:28
Priority:normal» critical

Yep, and I already have a hacky workaround for this somewhere laying around...

#6

Bryan76 - April 21, 2009 - 03:29

Is the workaround somewhere up here on drupal.org? If so, I'll double check, I must have missed it.

thanks, sun!

#7

slosa - April 23, 2009 - 14:12

subscribing same problem

#8

guix - April 29, 2009 - 18:21

Subscribe

#9

sun - August 11, 2009 - 20:29
Status:active» fixed

Thanks for reporting, reviewing, and testing! Committed attached patch to 6.x-2.x.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

AttachmentSize
inline-HEAD.node-save.patch 2.17 KB

#10

System Message - August 25, 2009 - 20:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.