I submit this patch strictly from a recent experience I had when I was trying to make use of the $reset parameter. In my case, I was writing an import script where lines of CSV were being parsed from a file. Each line of CSV had the potential to alter the taxonomy of an existing node. With the data we were getting for this import script, multiple lines in the data were adding to the taxonomy of an existing node. Keeping this in mind, I would call node_load($nid, NULL, TRUE), where the 'TRUE' in the call was the $reset parameter (this loaded node would be saved at the end of the loop). Unfortunately, I discovered, the node_invoke_nodeapi() and node_invoke() functions did not pass the $reset parameter to the node hooks. In my case, this was a problem, because taxonomy_nodeapi() relies on (in a helper function) a php static array when loading the taxonomy for a node. Of course, if the taxonomy of a node has changed during the execution of a script, a later loading would only return the first array of taxonomy terms loaded for the node, in spite of the $reset parameter being set to TRUE.

Of course, for this patch to be useful, other core modules will need to make use of the $revision and $reset parameters in their node hooks. I am willing to submit patches to this end if this one is accepted.

I also argue that this is the way to go just to make the loading function consistent across the hooks.

-Ankur

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ankur’s picture

Any thoughts on this? I'm just wondering what might be the point of having a $reset paramter to node_load() if that parameter doesn't get passed via node_invoke() and node_invoke_nodeapi(). The point of resetting when loading a node is that things in the node have changed within the lifetime of a single running of a script (or page serve). Currently, the $reset parameter to node_load() only resets the static $nodes array within node_load().

There would be much more consistency (and usefulness for a $reset param) if the hook_load()s and the hook_nodeapi()s (for $op == 'load') were able to receive their own reset parameter and became consistent w/ the node_load() by maintaining their own static arrays that respect the $reset parameter.... and the $revision parameter (which I haven't mentioned at all in this comment).

-Ankur

StevenPatz’s picture

Status: Active » Needs review
ankur’s picture

Status: Needs review » Needs work

Actually, if you look at the code for node_load(), passing the $revision param thru to the hooks is not necessary because, by the time to node_invoke() and node_invoke_nodeapi() happen, $node->vid will be set. So, patch needs to be rewritten to only pass along the $reset parameter.

-Ankur

drumm’s picture

Yep, don't need $revision.

The code for handling this in the taxonomy module would be a good addition to the patch.

ankur’s picture

Status: Needs work » Needs review
FileSize
2.32 KB

Here's an updated patch that removes the redundant revision parameter and also includes the changes to the taxonomy module.

-Ankur

catch’s picture

Version: 6.x-dev » 7.x-dev

This still applies with a big offset, bumping to the D7 queue.

ankur’s picture

Priority: Normal » Critical

What?! I figured this patch would've seen more review/comments and gotten more consideration, seeing as to how the original revision of this patch was submitted just two weeks after the Drupal 5 release. Oh well. I guess there aren't that many people out there that are writing import scripts.

This patch is nothing major and is pretty straight forward. Maybe it's one of those petty things oriented on small details that gets swept under the rug in favor of things more worthy of a press-release. Oh well.

-Ankur

StevenPatz’s picture

Priority: Critical » Normal

hardly critical.

R.Muilwijk’s picture

FileSize
2.34 KB

In your patch you reset the complete static. I don't think this should be done cause the reset is always called with a node and there for you know what node to delete.

I made up a new patch which only resets that node. Also I ran the tests which didn't give me any problems.

ankur’s picture

I think it's a good idea myself to only reset the internal cache for the nid on which the 'load' op is being called. However, if we're going to have that convention here, then we should probably also make it consistent with what's going on in the node_load() function defined in node.module. That function also maintains a static variable that is an array of cached nodes. Currently, that array is entirely reset everytime node_load() is called with a the reset parameter set to true.

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

ankur’s picture

Category: feature » bug
marcingy’s picture

Version: 7.x-dev » 8.x-dev
Category: bug » task

This is a task in my opinion, moving to d8.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)

Wonder if this is a valid task for node in D10?

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.