Skip to content

Commit 30bf9df

Browse files
authored
Fix guardian import (#4612)
1 parent 0fe0e1e commit 30bf9df

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

rest_framework/compat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ def value_from_object(field, obj):
207207
try:
208208
if 'guardian' in settings.INSTALLED_APPS:
209209
import guardian
210-
import guardian.shortcuts # Fixes #1624
211210
except ImportError:
212211
pass
213212

rest_framework/filters.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ def __init__(self):
289289
perm_format = '%(app_label)s.view_%(model_name)s'
290290

291291
def filter_queryset(self, request, queryset, view):
292+
# We want to defer this import until run-time, rather than import-time.
293+
# See https://github.com/tomchristie/django-rest-framework/issues/4608
294+
# (Also see #1624 for why we need to make this import explicitly)
295+
from guardian.shortcuts import get_objects_for_user
296+
292297
extra = {}
293298
user = request.user
294299
model_cls = queryset.model
@@ -302,4 +307,4 @@ def filter_queryset(self, request, queryset, view):
302307
extra = {'accept_global_perms': False}
303308
else:
304309
extra = {}
305-
return guardian.shortcuts.get_objects_for_user(user, permission, queryset, **extra)
310+
return get_objects_for_user(user, permission, queryset, **extra)

0 commit comments

Comments
 (0)