Skip to content

Commit 762a30d

Browse files
committed
Merge branch 'master' of github.com:tomchristie/django-rest-framework
2 parents f9c61e8 + cab9818 commit 762a30d

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

docs/tutorial/quickstart.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ Rather than write multiple views we're grouping together all the common behavior
8383

8484
We can easily break these down into individual views if we need to, but using viewsets keeps the view logic nicely organized as well as being very concise.
8585

86-
For trivial cases you can simply set a `model` attribute on the `ViewSet` class and the serializer and queryset will be automatically generated for you. Setting the `queryset` and/or `serializer_class` attributes gives you more explicit control of the API behaviour, and is the recommended style for most applications.
87-
8886
## URLs
8987

9088
Okay, now let's wire up the API URLs. On to `tutorial/urls.py`...
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Optional packages which may be used with REST framework.
22
markdown==2.5.2
3-
django-guardian==1.2.5
3+
django-guardian==1.3.0
44
django-filter==0.10.0

rest_framework/filters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,7 @@ def filter_queryset(self, request, queryset, view):
198198
'model_name': get_model_name(model_cls)
199199
}
200200
permission = self.perm_format % kwargs
201-
return guardian.shortcuts.get_objects_for_user(user, permission, queryset)
201+
if guardian.VERSION >= (1, 3):
202+
# Maintain behavior compatibility with versions prior to 1.3
203+
extra = {'accept_global_perms': False}
204+
return guardian.shortcuts.get_objects_for_user(user, permission, queryset, **extra)

rest_framework/serializers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ def save(self, **kwargs):
153153
'You cannot call `.save()` on a serializer with invalid data.'
154154
)
155155

156+
# Guard against incorrect use of `serializer.save(commit=False)`
157+
assert 'commit' not in kwargs, (
158+
"'commit' is not a valid keyword argument to the 'save()' method. "
159+
"If you need to access data before committing to the database then "
160+
"inspect 'serializer.validated_data' instead. "
161+
"You can also pass additional keyword arguments to 'save()' if you "
162+
"need to set extra attributes on the saved model instance. "
163+
"For example: 'serializer.save(owner=request.user)'.'"
164+
)
165+
156166
validated_data = dict(
157167
list(self.validated_data.items()) +
158168
list(kwargs.items())
@@ -611,6 +621,16 @@ def save(self, **kwargs):
611621
"""
612622
Save and return a list of object instances.
613623
"""
624+
# Guard against incorrect use of `serializer.save(commit=False)`
625+
assert 'commit' not in kwargs, (
626+
"'commit' is not a valid keyword argument to the 'save()' method. "
627+
"If you need to access data before committing to the database then "
628+
"inspect 'serializer.validated_data' instead. "
629+
"You can also pass additional keyword arguments to 'save()' if you "
630+
"need to set extra attributes on the saved model instance. "
631+
"For example: 'serializer.save(owner=request.user)'.'"
632+
)
633+
614634
validated_data = [
615635
dict(list(attrs.items()) + list(kwargs.items()))
616636
for attrs in self.validated_data

0 commit comments

Comments
 (0)