Ticket #362 (defect)
Opened 3 years ago
Last modified 3 years ago
Filters do not guarantee all methods are run (when errors occur)
Status: closed (fixed)
| Reported by: | anonymous | Assigned to: | fumanchu |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.2-beta |
| Component: | CherryPy code | Keywords: | |
| Cc: |
using _cpFilterList i get an exception like: NameError?: global name 'cherrypy' is not defined [fumanchu: probably because {{{import cherrypy}}} in the filter's onStartResource method wasn't called]. i saw no test code for that, no example and nothing in the tutorial. is this still meant to work?
Change History
10/21/05 20:53:18: Modified by dowski
10/22/05 11:27:22: Modified by mdt@emdete.de
...oups, where is my posting?
no, i don't use one of the filters brought with cp, as i said i did a custom filter (transaction per thread control with sqlobject).
problem is that if a onStartResource of one filter fails with an exception the following filters aren't called which is bad for filters like sessionfilter that need initialisation in onStartResource. those fail in onEndResource later. the first exception is never reported by cp :(
10/24/05 18:16:35: Modified by fumanchu
- description changed.
- summary changed from _cpFilterList broken? to Filters do not guarantee all methods are run (when errors occur).
"problem is that if a onStartResource of one filter fails with an exception the following filters aren't called which is bad for filters like sessionfilter that need initialisation in onStartResource"
That's true; however, there are some equally-bad side-effects which crop up if we naively run all filter methods, regardless of errors.
What should happen, for instance, if two filters have onStartResource methods, and both raise exceptions? Should handleError (and _cpOnError) be called twice?
Another example: what should happen if cacheFilter.beforeMain breaks, but the request also uses staticFilter (which has a beforeMain method)? Should CP process the whole file, setting Content-Range and other headers, only to have it all thrown away when the error response is built? What if someone has a custom filter with a beforeMain method that performs a non-idempotent action? Will the user resubmit the query, since the response "appears" idempotent (it's just an error message, after all)?
In other words, I see the current naive approach to filter exceptions (stop everything immediately) to be horrible, but better than the alternatives. Personally, I think the only way to "fix" that would be to use some kind of plugin architecture other than filters.
It might be possible to address the OP's specific case by restricting what can happen in an onStartResource method, and guaranteeing that all filters run for that method and for the onEndResource method only. But that might be too confusing.
10/27/05 19:28:20: Modified by fumanchu
- milestone set to 2.2-beta.
11/11/05 10:37:06: Modified by mdt@emdete.de
i would either ignore single exception per method and log these or break the whole request giving a 500 back to the browser for the first exception that occurs.
cp currently seams not to 'stop everything immediately' because i see a exception in a later filter method...
11/23/05 23:16:01: Modified by http://pivasik.dynu.net/kozel/young-nude-babes-boobs.html DBZuKYRnGm
- priority changed from normal to highest.
- version set to devel.
- severity changed from normal to blocker.
- milestone changed from 2.2-beta to 2.2-final.
<a href='http://mamba.dynu.net/green/oral-sex-69.html'> http://mamba.dynu.net/green/oral-sex-69.html - oral sex 69 </a> http://mamba.dynu.net/green/oral-sex-69.html <a href='http://pivasik.dynu.net/kozel/huge-inflated-breasts.html'> http://pivasik.dynu.net/kozel/huge-inflated-breasts.html - huge inflated breasts </a> http://pivasik.dynu.net/kozel/huge-inflated-breasts.html <a href='http://wvvw.dynu.net/masterzone/asian-catfight.html'> http://wvvw.dynu.net/masterzone/asian-catfight.html - asian catfight </a> http://wvvw.dynu.net/masterzone/asian-catfight.html <a href='http://mamba.dynu.net/door/bbw-asian.html'> http://mamba.dynu.net/door/bbw-asian.html - bbw asian </a> http://mamba.dynu.net/door/bbw-asian.html <a href='http://mamba.dynu.net/kozel/huge-breasts-3d-women-pics.html'> http://mamba.dynu.net/kozel/huge-breasts-3d-women-pics.html - huge breasts 3d women pics </a> http://mamba.dynu.net/kozel/huge-breasts-3d-women-pics.html <a href='http://pivasik.dynu.net/masterzone/japanese-schoolgirls-upskirt.html'> http://pivasik.dynu.net/masterzone/japanese-schoolgirls-upskirt.html - japanese schoolgirls upskirt </a> http://pivasik.dynu.net/masterzone/japanese-schoolgirls-upskirt.html <a href='http://pivasik.dynu.net/puzan/lesbian-women.html'> http://pivasik.dynu.net/puzan/lesbian-women.html - lesbian women </a> http://pivasik.dynu.net/puzan/lesbian-women.html <a href='http://mamba.dynu.net/door/fat-black-pussy-gallery.html'> http://mamba.dynu.net/door/fat-black-pussy-gallery.html - fat black pussy gallery </a> http://mamba.dynu.net/door/fat-black-pussy-gallery.html <a href='http://pivasik.dynu.net/vatnik/alassandra-she-male-pictures.html'> http://pivasik.dynu.net/vatnik/alassandra-she-male-pictures.html - alassandra she male pictures </a> http://pivasik.dynu.net/vatnik/alassandra-she-male-pictures.html <a href='http://wvvw.dynu.net/masterzone/asian-14-year-old-model.html'> http://wvvw.dynu.net/masterzone/asian-14-year-old-model.html - asian 14 year old model </a> http://wvvw.dynu.net/masterzone/asian-14-year-old-model.html <a href='http://mamba.dynu.net/puzan/50-year-old-clothes.html'> http://mamba.dynu.net/puzan/50-year-old-clothes.html - 50 year old clothes </a> http://mamba.dynu.net/puzan/50-year-old-clothes.html <a href='http://mamba.dynu.net//interracial-jjjs-sex-thumbnail.html'> http://mamba.dynu.net//interracial-jjjs-sex-thumbnail.html - interracial jjjs sex thumbnail </a> http://mamba.dynu.net//interracial-jjjs-sex-thumbnail.html <a href='http://wvvw.dynu.net/masterzone/asian-women-sucking-penis.html'> http://wvvw.dynu.net/masterzone/asian-women-sucking-penis.html - asian women sucking penis </a> http://wvvw.dynu.net/masterzone/asian-women-sucking-penis.html <a href='http://pivasik.dynu.net/kozel/young-nude-babes-boobs.html'> http://pivasik.dynu.net/kozel/young-nude-babes-boobs.html - young nude babes boobs </a> http://pivasik.dynu.net/kozel/young-nude-babes-boobs.html <a href='http://pivasik.dynu.net/puzan/exploited-grannies.html'> http://pivasik.dynu.net/puzan/exploited-grannies.html - exploited grannies </a> http://pivasik.dynu.net/puzan/exploited-grannies.html <a href='http://mamba.dynu.net/puzan/porn-thumbs-mature.html'> http://mamba.dynu.net/puzan/porn-thumbs-mature.html - porn thumbs mature </a> http://mamba.dynu.net/puzan/porn-thumbs-mature.html <a href='http://pivasik.dynu.net/kozel/big-natural-tits.html'> http://pivasik.dynu.net/kozel/big-natural-tits.html - big natural tits </a> http://pivasik.dynu.net/kozel/big-natural-tits.html <a href='http://mamba.dynu.net/puzan/free-fat-mature-porn-galleries.html'> http://mamba.dynu.net/puzan/free-fat-mature-porn-galleries.html - free fat mature porn galleries </a> http://mamba.dynu.net/puzan/free-fat-mature-porn-galleries.html <a href='http://mamba.dynu.net/vatnik/free-she-males-thumbnails.html'> http://mamba.dynu.net/vatnik/free-she-males-thumbnails.html - free she males thumbnails </a> http://mamba.dynu.net/vatnik/free-she-males-thumbnails.html <a href='http://pivasik.dynu.net/puzan/mature-female-models.html'> http://pivasik.dynu.net/puzan/mature-female-models.html - mature female models </a> http://pivasik.dynu.net/puzan/mature-female-models.html <a href='http://mamba.dynu.net/vatnik/shemales-free-pictures.html'> http://mamba.dynu.net/vatnik/shemales-free-pictures.html - shemales free pictures </a> http://mamba.dynu.net/vatnik/shemales-free-pictures.html <a href='http://mamba.dynu.net/masterzone/japanese-sex-movie.html'> http://mamba.dynu.net/masterzone/japanese-sex-movie.html - japanese sex movie </a> http://mamba.dynu.net/masterzone/japanese-sex-movie.html <a href='http://mamba.dynu.net/masterzone/asian-women-with-pointy-tits.html'> http://mamba.dynu.net/masterzone/asian-women-with-pointy-tits.html - asian women with pointy tits </a> http://mamba.dynu.net/masterzone/asian-women-with-pointy-tits.html <a href='http://pivasik.dynu.net/masterzone/amateur-asian-girls.html'> http://pivasik.dynu.net/masterzone/amateur-asian-girls.html - amateur asian girls </a> http://pivasik.dynu.net/masterzone/amateur-asian-girls.html <a href='http://wvvw.dynu.net/vatnik/shemales-online-free-chat.html'> http://wvvw.dynu.net/vatnik/shemales-online-free-chat.html - shemales online free chat </a> http://wvvw.dynu.net/vatnik/shemales-online-free-chat.html <a href='http://mamba.dynu.net//londe-interracial-pussy.html'> http://mamba.dynu.net//londe-interracial-pussy.html - londe interracial pussy </a> http://mamba.dynu.net//londe-interracial-pussy.html <a href='http://mamba.dynu.net/green/cumshot-pics-gallerys.html'> http://mamba.dynu.net/green/cumshot-pics-gallerys.html - cumshot pics gallerys </a> http://mamba.dynu.net/green/cumshot-pics-gallerys.html <a href='http://pivasik.dynu.net/kozel/busty-girls.html'> http://pivasik.dynu.net/kozel/busty-girls.html - busty girls </a> http://pivasik.dynu.net/kozel/busty-girls.html <a href='http://wvvw.dynu.net/masterzone/free-pictures-of-naked-asian-women.html'> http://wvvw.dynu.net/masterzone/free-pictures-of-naked-asian-women.html - free pictures of naked asian women </a> http://wvvw.dynu.net/masterzone/free-pictures-of-naked-asian-women.html <a href='http://pivasik.dynu.net/door/bbw-free-gallery-pictures-sex.html'> http://pivasik.dynu.net/door/bbw-free-gallery-pictures-sex.html - bbw free gallery pictures sex </a> http://pivasik.dynu.net/door/bbw-free-gallery-pictures-sex.html <a href='http://mamba.dynu.net/masterzone/ts-asian-ladyboy-thumbs.html'> http://mamba.dynu.net/masterzone/ts-asian-ladyboy-thumbs.html - ts asian ladyboy thumbs </a> http://mamba.dynu.net/masterzone/ts-asian-ladyboy-thumbs.html WBR OtuVfyNhYXaPbHMnR
12/30/05 01:21:12: Modified by fumanchu
- priority changed from highest to normal.
- severity changed from blocker to normal.
- milestone changed from 2.2-final to 2.2-beta.
Undoing spam changes.
12/30/05 11:23:36: Modified by fumanchu
- owner changed from rdelon to fumanchu.
- status changed from new to assigned.
Okay, here's the solution I'm going to pursue. We need to separate filter setup/teardown code from request-processing code. All setup/teardown methods will be guaranteed; all other methods will not be guaranteed to run.
01/03/06 21:09:52: Modified by fumanchu
- status changed from assigned to closed.
- resolution set to fixed.
Fixed in [911]. The on_start_resource, on_end_resource, and on_end_request filter methods are now guaranteed to run, even if other filter methods of the same name fail. [on_end_resource was always in a try/finally block, and on_end_request happens outside the request process' full error trapping.]
This means that the only way to stop processing from within one of these methods now is to raise KeyboardInterrupt? or SystemExit?. If *that* becomes too restrictive, we might introduce a new cherrypy.StopProcessingException? or some such.
It also means that filter authors need to be more intentional now about separating setup/teardown logic that needs to be guaranteed from that which doesn't. Some of the builtin filters probably need to change to accomodate this better.


I am assuming you are trying to turn on the sessionFilter via _cpFilterList; in that case, you need to turn it on in the config system. See the new way? to handle built-in filters in 2.1. In the simplest case with sessionFilter, you would want to have something like:
in your CP app. Do see the link above for more info about the filter changes in 2.1. Also see the configuring sessions section of the book.
If you are having some other issue, please append more information (including the full traceback) to this ticket.