In grok (and potentially other frameworks working with fanstatic), if an error occurs during the handling of a request, the current NeededResources is not reset.
As a result, the NeededResources are injected in the error page which is generated by grok.
One way to fix this is to look for an event to hook into, like we do in zope.fanstatic for setting the base_url at the end of the request, but unfortunately there is no //i-am-now-going-to-render-an-error-view// event defined nor fired by the publication process.
One option I see is to reset the NeededResources at the beginning of rendering the error page. This should be the responsibility of the zope.fanstatic, megrok.fanstatic package or integrated into grok. Doing this would introduce a hard dependency on fanstatic in grok, but this discussion is not part of the fanstatic package.
Another option would be to move exception handling out of grok into a WSGI component. I personally wouldn't like that, as in my applications we share code between regular views and exception views.
Should fanstatic supply infrastructure for resetting the NeededResources? We could add a //clear// method to the NeededResources class.
What do you think? Do you see another option of resetting the NeededResources on handling errors during a request cycle?