Skip to content

Commit 1d2fba9

Browse files
vikalpjtomchristie
authored andcommitted
Fix issues with routers for custom list-route and detail-routes (#4229)
1 parent d41ddc9 commit 1d2fba9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

rest_framework/routers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ def get_routes(self, viewset):
144144
145145
Returns a list of the Route namedtuple.
146146
"""
147-
known_actions = flatten([route.mapping.values() for route in self.routes if isinstance(route, Route)])
147+
# converting to list as iterables are good for one pass, known host needs to be checked again and again for
148+
# different functions.
149+
known_actions = list(flatten([route.mapping.values() for route in self.routes if isinstance(route, Route)]))
148150

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy