Skip to content

Commit

Permalink
Fix issues with routers for custom list-route and detail-routes (#4229)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikalpj authored and tomchristie committed Jun 29, 2016
1 parent d41ddc9 commit 1d2fba9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rest_framework/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def get_routes(self, viewset):
Returns a list of the Route namedtuple.
"""
known_actions = flatten([route.mapping.values() for route in self.routes if isinstance(route, Route)])
# converting to list as iterables are good for one pass, known host needs to be checked again and again for
# different functions.
known_actions = list(flatten([route.mapping.values() for route in self.routes if isinstance(route, Route)]))

# Determine any `@detail_route` or `@list_route` decorated methods on the viewset
detail_routes = []
Expand All @@ -154,6 +156,7 @@ def get_routes(self, viewset):
httpmethods = getattr(attr, 'bind_to_methods', None)
detail = getattr(attr, 'detail', True)
if httpmethods:
# checking method names against the known actions list
if methodname in known_actions:
raise ImproperlyConfigured('Cannot use @detail_route or @list_route '
'decorators on method "%s" '
Expand Down

0 comments on commit 1d2fba9

Please sign in to comment.