I have found a few situations where template reloading mechanism is working wrong and produces an error.
Example of situation 1:
- Templates: A, B, C
- Extends: B extends A, C extends A, i.e. B and C depend on A
To reproduce the error:
- load page with template B
- then load page with template C
- then again load page with template B --> a NoneType exception will be raised.
What's wrong:
- When C sees that A was changed, it delete A's module from sys.modules.
- Then B loads and it tries to get A's module info from sys.modules, but it doesn't exist anymore and a KeyError exception occurrs.
- As a result the load_template method fails and we get an exception.
Example of situation 2:
- Templates: A, B, C
- Extends: C extends B, B extends A, i.e. A -> B -> C
To reproduce the error:
- load page with template C
- then touch template A
- then load page with template C again. An exception will raised.
What's wrong:
- When loading module C the caching max mtime for each template depends on it bases.
- Let's assume that A has max mtime. mtime<A> = t1, mtime<B> = mtime<A>, mtime<C> = mtime<A>.
- Next we load template B. In this process we redefine mtimes of some base templates which stored max mtime. Now mtime<B> != mtime<A> --> load_template method fails again.
I've attach patch which fix all this bugs.