Download & Extend

Blog Theme causes Fatal Errors in other modules, due to bad hook_init() implementation

Project:Blog Theme
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

I'm not using Blog Theme myself, but my search for a possible culprit of weird Fatal Errors, that some users experienced with Category module, led me to this module. For more details, see #338750: Fatal errors - category.inc sometimes not loaded?.

The problem is, that Blog Theme does node_load() inside hook_init() implementation. That's wrong, and more so with module weight of zero, and module name early in the alphabet. Now what happens is, that many modules (with names ranging from C to Z with default weight, and anything with a positive weight) are still waiting for their hook_init() implementations to be executed, while Blog Theme calls node_load(), and therefore hook_nodeapi() fires in all modules, including these not-yet-initialized. In the case of category.module, the initialization involves also loading of an additional include file. Having hook_nodeapi() invoked before that leads to important functions missing, and therefore throws a Fatal Error.

I believe that Blog Theme should retrieve the needed information about nodes (which is, as far as I can see, only just type and uid) through a simple query against {node} table, which would be additionally a performance improvement.

I wonder whether user_load() is also a problem (I didn't test that part).

I proposed a temporary fix in category module (above-linked issue), which is nothing else than another, redundant require_once(), just for the sake of stopping influx of critical bug reports. But it's quite possible that this breaks more modules, and I believe that the problem needs to be fixed at it's source most importantly.

Comments

#1

Status:active» needs review

Attached is a patch against the current blog_theme HEAD that replaces node_load() with query statements.

AttachmentSize
blog_theme.module.patch 1.77 KB

#2

I took over maintenance for a related module called ThemeKey which had a similar issue:
#684868: Imagecache breaks, avoid node_load() in hook_init()

Thanks for the hint.

#3

Don't working properly with Themekey.

nobody click here