Re: bug in RandomPageModuleMixin.load_page
Andrew McNamara <[email protected]> Thu, 27 May 2010 17:46:21 +1000
| Newsgroups | gmane.comp.web.albatross.general |
|---|---|
| Message-ID | <1274946381.10296.11.camel@longblack> |
--=-ulfIGsMm2mLUHDvqv0vJ
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
On Fri, 2010-05-14 at 21:50 +0300, Nickolay Savchenko wrote:
> load_page method of RandomPageModuleMixin seems to have a bug. If URL
> has dots this method doesn't catch ApplicationError correctly, and
> server returns 500 error instead of 404.
>
> Traceback is following:
>
> 2010-04-07 17:37:32.215924: //phpMyAdmin/config/config.inc.php?c=uptime
> Traceback (most recent call last):
> File "/var/www/ivi/website/modules/app.py", line 167, in run
> self.load_page(ctx)
> File "/usr/lib/python2.5/site-packages/albatross/randompage.py",
> line 29, in load_page
> self.load_page_module(ctx, page)
> File "/usr/lib/python2.5/site-packages/albatross/app.py", line 437,
> in load_page_module
> raise ApplicationError('%s (in %s)' % (e, mod_dir))
> ApplicationError: No module named php (in
> /var/www/ivi/website/pages/config/config/inc)
>
> This can be easily fixed with attached patch.
Thanks for the bug report! I've implemented a slightly different fix
that creates an ApplicationError subclass called PageNotFound and thus
avoids the need for searching in strings. Can you try this out and let
me know if it fixes the problem equally well (sorry, I haven't had a
chance to replicate it yet)?
--
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/
--=-ulfIGsMm2mLUHDvqv0vJ
Content-Disposition: attachment; filename="albatross-randompage-patch"
Content-Type: text/x-patch; name="albatross-randompage-patch"; charset="UTF-8"
Content-Transfer-Encoding: 7bit
Index: albatross/common.py
===================================================================
--- albatross/common.py (revision 16031)
+++ albatross/common.py (working copy)
@@ -36,6 +36,9 @@
class TemplateLoadError(ApplicationError):
pass
+class PageNotFound(ApplicationError):
+ pass
+
class SessionExpired(UserError):
pass
Index: albatross/randompage.py
===================================================================
--- albatross/randompage.py (revision 16031)
+++ albatross/randompage.py (working copy)
@@ -12,7 +12,7 @@
from albatross.app import Application, PageModuleMixin, SimpleAppContext,\
SessionAppContext
from albatross.session import SessionServerAppMixin
-from albatross.common import ApplicationError
+from albatross.common import PageNotFound
class RandomPageModuleMixin(PageModuleMixin):
@@ -27,9 +27,7 @@
self.__page_found = 1
try:
self.load_page_module(ctx, page)
- except ApplicationError, e:
- if not str(e).startswith('No module named %s' % page.split('/')[-1]):
- raise
+ except PageNotFound, e:
ctx.locals.page_name = page
self.__page_found = 0
if self.__page_found:
Index: albatross/app.py
===================================================================
--- albatross/app.py (revision 16031)
+++ albatross/app.py (working copy)
@@ -433,7 +433,7 @@
try:
f, filepath, desc = imp.find_module(mod_path[-1], [mod_dir])
except ImportError, e:
- raise ApplicationError('%s (in %s)' % (e, mod_dir))
+ raise PageNotFound('%s (in %s)' % (e, mod_dir))
try:
module = imp.load_module(mod_name, f, filepath, desc)
finally:
--=-ulfIGsMm2mLUHDvqv0vJ
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Albatross-users mailing list
[email protected]
https://www.object-craft.com.au/cgi-bin/mailman/listinfo/albatross-users
--=-ulfIGsMm2mLUHDvqv0vJ--