mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-30 01:49:50 +03:00
routers: add check on register
Trying to register new routes on a router after having accessed the router `urls` attribute leads to surprising results. The route is added without error to the router's `registry` but the urls are not updated, because they are cached in `_urls`. This commit prevents registering new routes after `_urls` is created.
This commit is contained in:
parent
c049777dc7
commit
f9c9dad0ce
|
@ -86,6 +86,8 @@ class BaseRouter(six.with_metaclass(RenameRouterMethods)):
|
|||
self.registry = []
|
||||
|
||||
def register(self, prefix, viewset, basename=None, base_name=None):
|
||||
assert not hasattr(self, '_urls'), (
|
||||
"You should register all your urls before accessing self.urls.")
|
||||
if base_name is not None:
|
||||
msg = "The `base_name` argument is pending deprecation in favor of `basename`."
|
||||
warnings.warn(msg, PendingDeprecationWarning, 2)
|
||||
|
|
Loading…
Reference in New Issue
Block a user