1

I have a site with a large number of modules (100+) installed and I have an issue with my rules firing twice, which appears to be caused by user_save() being called twice. (I was able to confirm this by adding a dpm($account) in user_save(), which is printed to the screen twice on my dev site when I log in as an authenticated user and update that user's profile.

Now I'd like to find which contrib module is caused user_save() to be called twice (of course this assumes it is a contrib module). I'm not a developer so I'm getting stuck. I have Netbeans set up with Xdebug and I set a breakpoint on user_save(). Then I started the debugger and logged in and updated a user account, but when I look at the call stack I see the following:

/mysite/modules/user/user.module.include_once:424 /mysite/includes/bootstrap.inc.drupal_load:1126
/mysite/sites/all/modules/contrib/devel/devel.module.devel_boot:616
/mysite/includes/module.inc.call_user_func_array:833
/mysite/includes/module.inc.module_invoke:833 /mysite/includes/bootstrap.inc.bootstrap_invoke_all:1097
/mysite/includes/bootstrap.inc._drupal_bootstrap_page_header:2454 /mysite/includes/bootstrap.inc.drupal_bootstrap:2214
/mysite/index.php.{main}:20

And then when user_save() is called again (in the same page load) I see exactly the same output. If it is a contrib module that is causing user_save() to be called twice, how can I find out which one it is?

  • 2
    Adding watchdog('debug', '<pre>' . print_r(debug_backtrace(), TRUE) . '</pre>'); into an implementation of hook_user_insert() and/or hook_user_update() might be a good start, it should give you a trace of what functions were called for each run up to user_save(). Analysing that should give you an idea of what's instigating the calls at least – Clive Jan 10 '13 at 13:28
  • @Clive Thanks, I was able to add the call to watchdog in hook_user_update(). However, I had to enable syslog because it overloaded the watchdog reports screen; a single save of a user profile generated 685033 lines of text in the syslog file. Is there some way to look at the file and get meaningful information, because there's no way I can read a half million lines of text... – Patrick Kenny Jan 16 '13 at 14:28
1

It turned out Rules was the culprit. I didn't realized that using the Set a data value action could cause user_save() to be called twice.

  • Thanks for putting this answer up here, this is really helpful to know! – DrCord May 9 '14 at 16:16
  • Is there a way to set values without re-triggering your rule and resulting in the double rule call? – DrCord May 9 '14 at 16:19
0

Try turning off devel. That shouldn't be calling anything that calls user save.

  • 1
    I don't think the OP is suggesting Devel's responsible, just that he's confirmed the problem by using Devel to ascertain that the function is being entered twice. – Clive Jan 10 '13 at 15:08
  • I thought we were looking at an xdebug stack which shows to me that user save is being called by something in devel_boot? – Jeremy French Jan 10 '13 at 15:37
  • Hmm yeah it does look that way, but looking at the code Devel doesn't actually invoke a call to user_save() at any point. The most recent item in the stack is the include_once call from drupal_load() (about half way down the function), which is called from devel_boot(). There's simply no scope for a call to user_load() anywhere in that process as far as I can tell (not saying you're wrong given the information, just that it doesn't make sense) – Clive Jan 10 '13 at 16:03
  • 1
    I do have Devel enabled on my dev site, but the problem occurs on production as well, where Devel is turned off. – Patrick Kenny Jan 11 '13 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.