mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 19:14:01 +03:00
Use RuntimeError, not AssertionError when guarding against direct View.queryset evalutation. Refs #3180.
This commit is contained in:
parent
36d8d3681a
commit
bdeb28944f
|
@ -121,7 +121,7 @@ class APIView(View):
|
||||||
"""
|
"""
|
||||||
if isinstance(getattr(cls, 'queryset', None), models.query.QuerySet):
|
if isinstance(getattr(cls, 'queryset', None), models.query.QuerySet):
|
||||||
def force_evaluation():
|
def force_evaluation():
|
||||||
raise AssertionError(
|
raise RuntimeError(
|
||||||
'Do not evaluate the `.queryset` attribute directly, '
|
'Do not evaluate the `.queryset` attribute directly, '
|
||||||
'as the result will be cached and reused between requests. '
|
'as the result will be cached and reused between requests. '
|
||||||
'Use `.all()` or call `.get_queryset()` instead.'
|
'Use `.all()` or call `.get_queryset()` instead.'
|
||||||
|
|
|
@ -541,5 +541,5 @@ class TestGuardedQueryset(TestCase):
|
||||||
|
|
||||||
view = QuerysetAccessError.as_view()
|
view = QuerysetAccessError.as_view()
|
||||||
request = factory.get('/')
|
request = factory.get('/')
|
||||||
with pytest.raises(AssertionError):
|
with pytest.raises(RuntimeError):
|
||||||
view(request).render()
|
view(request).render()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user