This is a little off the beaten path, but I was hoping someone could give me a suggestion as to where to focus my efforts:

I've been playing with getting CCK to work with project_issue and I've run into an odd behavior. I created two CCK fields: date and reference. Both fields show up fine in the insert and edit screens, but didn't seem to save on insert. Editing the node worked fine.

I looked in the database, and I was surprised to find that the information was there. After a lot of debugging, I tracked this down to an issue with how the data is set in the cache table. Some print_r() commands in content_load() show that the $node object isn't getting the CCK data at this point. Commenting out the cache check in content_load() makes the content show up.

Other nodes work fine, so I'm wondering if there is something in the project issue work flow that is causing this. I realize it's probably more in the realm of project module, but I wanted to post it here in case someone more familiar with CCK had any quick ideas on where to look.

For reference, here is the issue where I am discussing adding these fields to the follow-up form: http://drupal.org/node/137135

Thanks in advance.

Comments

seanbfuller’s picture

Well, I think I've tracked down why this is happening. I did some backtraces and some drupal_set_messages to track down the nodeapi workflow and noticed that there is an extra node_load being called before hook_nodeapi (load) is called. Here's the quick walk through of what happens:

  1. node_form_submit calls node_submit
  2. node_form_submit calls node_save
  3. node_save saves the basic node info
  4. node_save then calls node_invoke with a parameter of insert, which results in project_issue_insert being called. At the end of project_issue_insert it calls project_mail_notify (see below)
  5. node_save then calls node_invoke_nodeapi (insert)

The issue seems to be that the first line of project_mail_notify() is a call to node_load to get the project issue information. I think what's happening is that at this point in the code, we haven't invoked nodeapi() to save the extra information to the database. As a result, when we call node load, we call node_invoke_nodeapi(), then content_nodeapi(), then content_load(). The function content_load() sees that this is the first time we are loading this node and caches the empty cck information. Once we're done there, we return to node_save and call the nodeapi invoke, resulting in an empty cache, even though the data was saved.

Note that content_update includes a call to cache_clear_all(), which removes the problem when updating.

It seems like the issue is that there is no place to add the call to project_mail_notify to ensure that all the data was saved. Moving it to project_issue_issue_nodeapi() may help by moving the the call to node_load in that function to after the module_invoke_nodeapi() call.

A quick and dirty fix might be to add a call to cache_clear_all() in content_insert or project_issue_insert(), but both of these options seem messy. There might actually be an argument for a kind of hook_notify function in Drupal 6 that would be called directly from node_save after the nodeapi functions are invoked. This would make sure that everything had been saved and would also allow other modules to leverage this functionality. That's probably outside the scope of this issue, but I'd be willing to help write up an issue if others thought this was something useful moving forward. Can anyone think of a better place for this fix to happen?

To the wonderful maintainers of CCK, feel free to move this issue into the project_issue project if that makes more sense. I'll be posting a small note in the due date cck + project_issue issue listed above to notify others of what I've found.

Again, I know this is a bit off the beaten path, but hopefully it saves someone else out there some time.

yched’s picture

Nice debug tracing :-)
I'd be tempted to consider this a Project.module bug : having a node_load while in hook_insert and before hook_nodeapi('insert'à does not seem a right idea, and I'm not sure CCK should try to cover such cases.

The right fix could be, as you suggest, to move the call to project_mail_notify into nodeapi('insert') (provided project.module is assigned a greater weight than content.module). Or maybe having a hook_nodeapi('saved'...) would be cool ?

The $node is available during hook_nodeapi('insert') without the need for any node_load, BTW - including the CCK fields, since they get included in content_nodeapi('submit').

I'll leave you or derek close this issue, though.

seanbfuller’s picture

Thanks for the response,

I can say that adding the following line at the bottom of project_issue_insert() in issue.inc, after project_mail_notify(), fixed the problem for me:

  cache_clear_all('content:'. $node->nid .':'. $node->vid, 'cache_content');

Obviously this is not the correct fix, but I was able to confirm that this works. I'll see what derek has to say and clean this from your queue if he doesn't get a chance to get to it. I'd be tempted to make this over to project_issue, but I'll let him do it.

yched’s picture

Yep.

Editing myself :
"The right fix could be, as you suggest, to move the call to project_mail_notify into nodeapi('insert')", with no need for any weight considerations since, as I wrote two lines later, cck fields are added in 'submit' op...

dww’s picture

Project: Content Construction Kit (CCK) » Project issue tracking
Version: 5.x-1.5 » 5.x-2.x-dev
Component: content.module » Issues
Category: support » bug
Priority: Minor » Normal
Status: Active » Needs review
StatusFileSize
new656 bytes

yup, this is a project_issue bug, not CCK's fault. ;) it's amazing how many gems live in the project* codebase... this particular bug can be traced back to:

----------------------------
revision 1.11
date: 2003-10-01 13:00:38 +0000;  author: kjartan;  state: Exp;  lines: +6 -15;
- Still strugling with UTF-8
----------------------------

reviewing the diff for that change, it's not clear how the node_load() relates at all to the UTF-8 fixes in other parts of the patch... i think he was just trying stuff and either accidentally left that in, or assumed it wouldn't hurt...

anyway, i'm totally down with removing the call to node_load() in project_mail_notify(), since we already have all the node fields we care about in the $node object by that point, anyway. sean, please try the attached patch and see if your woes go away (and the email notifications/subscriptions still work). if so, set this to RTBC and i'll commit it ASAP.

thanks for the great job debugging this, and sorry for the delay on reading the results of your investigation. ;)

cheers,
-derek

seanbfuller’s picture

Status: Needs review » Reviewed & tested by the community

That seemed to work fine for me. The due date seems showing up correctly during insert. There doesn't seem to be anything missing from the edit version of the node object as opposed to the loaded node. There shouldn't be, that was my only concern.

I'm going to create an additional minor issue in regards to getting cck information to show up in the email.

I think this one is RTBC.

dww’s picture

Status: Reviewed & tested by the community » Fixed

commited to HEAD, DRUPAL-4-7--2 and DRUPAL-4-7.
thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)