anonymous user getting error

dsp1 - March 10, 2007 - 04:29
Project:Devel
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Dave Reid
Status:closed
Description

Fatal error: Call to undefined function: drupal_add_js() in /home/xxx/public_html/sites/all/modules/devel/devel.module on line 166
also log showing sites/all/modules/devel/devel.css not found, even though it is there.

I have drupal 5.1, PHP 4.4.4, apache 1.3.37. only devel module enabled. not node access or macro.

My test machine running drupal 5.1, PHP 5.2, apache 1.3.33 does not have this error.

moving the devel folder out of the module folder allows login. also if logged in, and then logout you can use the back button to the user login and still login without having to move the devel folder.

thanks for all your hard work. this is a great module.

#1

Dave Reid - March 14, 2007 - 01:37
Assigned to:Anonymous» Dave Reid
Status:active» needs review

I'm guessing that since the annonymous users get cached versions, that some functions aren't available. When I added drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); to the beginning of the function devel_init() that anonymous browsing worked correctly. I've attached a patch but I haven't had time to investigate if there are any side-effects.

AttachmentSize
devel_15.patch 432 bytes

#2

dsp1 - March 14, 2007 - 08:36

right, I have Caching mode: Normal on the web site and Caching mode: Disabled on my test site.
I think I will wait to apply the patch to find out if there are any side effects.
thank you for your response.

#3

laken - March 26, 2007 - 15:32

subscribing

#4

Dave Reid - March 27, 2007 - 18:22
Status:needs review» reviewed & tested by the community

I'm very sure this is ready to commit. I haven't experienced any problems since the patch.

#5

dww - March 29, 2007 - 09:21
Status:reviewed & tested by the community» needs review

i'm not so sure. take a look at http://drupal.org/node/123951 which is the issue that led to that call to drupal_add_js() being inserted in the first place. i think there might be cases when you break something by always doing a drupal_bootstrap() in hook_init() -- that seems totally wonky to me.

in fact, if you read http://api.drupal.org/api/5/function/hook_init you'll see that adding functions in hook_init() is generally prone to these errors, and when you get them, it recommends moving the offending code to hook_menu(), instead.

honestly, i don't fully understand the implications of #123951 enough to say for sure, but i'm *positive* this at least needs more review, if not more work, before it can be committed...

hopefully moshe and/or ted will reply here with their thoughts...

#6

nicholasThompson - March 29, 2007 - 21:24

I've just upgraded www.thingy-ma-jig.co.uk to Drupal 5.1 and this bug was taking the entire site out for anon users. A suggestion by Mike Dixon was to use the user_access() function - so by wrapping the contents of devel_init() in a user_access() call like this...

<?php
function devel_init() {   
  if(
user_access('access devel information')) {
   
// ensure that jquery has been added to the page
   
drupal_add_js('', 'inline');
   
    if (
strstr($_SERVER['PHP_SELF'], 'update.php') || strstr($_GET['q'], 'autocomplete')) {
     
// update.php relies on standard error handler
   
}
    else {
     
register_shutdown_function('devel_shutdown');
      if (
variable_get('dev_mem', 0) && function_exists('memory_get_usage')) {
        global
$memory_init;
 
       
$memory_init = memory_get_usage();
      }
     
$handler = variable_get('devel_error_handler', DEVEL_ERROR_HANDLER_STANDARD);
      switch (
$handler) {
        case
DEVEL_ERROR_HANDLER_STANDARD:
         
// do nothing
         
break;
        case
DEVEL_ERROR_HANDLER_BACKTRACE:
         
set_error_handler('backtrace_error_handler');
          break;
        case
DEVEL_ERROR_HANDLER_NONE:
         
restore_error_handler();
          break;
      }
    }
  }
}
?>

... the error SEEMS to dissapear...

(I dont have diff facilities available right now)

Any thoughts on this?

#7

nicholasThompson - March 29, 2007 - 21:38

ignore me - this is not a fix... It took 10 minutes, but the page broke eventually.

Basically the same error as above.

Gonna try checking the global $user object...

#8

nicholasThompson - March 29, 2007 - 21:40

Much better solution (again suggested by Mike Dixon) is this:

<?php
if(function_exists('drupal_add_js'))
?>

That should nail it...

#9

dww - March 29, 2007 - 22:19
Status:needs review» fixed

moshe just removed the line entirely (if you freshly update from CVS), since he didn't think the drupal_add_js() was essential to the other functionality and fixes addressed in http://drupal.org/node/123951

i just tested, and this is already fixed with the latest code (revision 1.106.4.41 of devel.module). with page caching enabled, 1.106.4.40 killed the site for anonymous, and 1.106.4.41 works fine.

#10

dericknwq - March 31, 2007 - 07:56

With that line removed, isn't JQuery not included at all? I've enabled viewing of devel information for anonymous user on my test site and that wouldn't work. I think the problem right now is getting Devel to work with the Cache (Normal) turned for Anonymous (with access "access devel information"). Or rather, Devel does not play well with Cache turned on at all.

#11

Anonymous - April 14, 2007 - 08:02
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.