Ticket #706 (defect)
Opened 10 months ago
Last modified 3 months ago
Routes doesn't give 404
Status: closed (fixed)
| Reported by: | guest | Assigned to: | lawouach |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1 |
| Component: | CherryPy code | Keywords: | |
| Cc: |
When Routes is unable to find a route, it will throw: AttributeError?: MainController? instance has no attribute 'foo'
Example based on the cherrypy docs:
# -*- encoding: UTF-8 -*-
import os
import cherrypy
class MainController:
def index(self):
return "This is the main page"
class BlogController:
def index(self, entry_id):
return "This is blog entry no. %d" % int(entry_id)
def edit(self, entry_id):
return "This is an edit form for blog entry no. %d" % int(entry_id)
dispatcher = None
def setup_routes():
d = cherrypy.dispatch.RoutesDispatcher()
d.connect('blog', 'myblog/:entry_id/:action', controller=BlogController())
d.connect('main', ':action', controller=MainController())
dispatcher = d
return dispatcher
conf = {
'/': {
'request.dispatch': setup_routes()
}
}
cherrypy.config.update(conf)
cherrypy.quickstart(None, config=conf)
Sending /foo produces a 500 AttributeError?.
The problem is on line 323 of _cpdispatch.py: handler = getattr(controller, action)
This should become: handler = getattr(controller, action, None)
This will cause a default value of None instead an exception, and this None will result in a 404.
Change History
01/16/08 16:41:05: Modified by lawouach
- owner changed from rdelon to lawouach.
- status changed from new to assigned.
- milestone set to 3.1.
02/18/08 13:19:22: Modified by lawouach
- status changed from assigned to closed.
- resolution set to fixed.


Fixed for the current trunk (3.1) in [1893] and in [1894] for the 3.0.x branch.