@@ -153,6 +153,16 @@ def save(self, **kwargs):
153
153
'You cannot call `.save()` on a serializer with invalid data.'
154
154
)
155
155
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
+
156
166
validated_data = dict (
157
167
list (self .validated_data .items ()) +
158
168
list (kwargs .items ())
@@ -611,6 +621,16 @@ def save(self, **kwargs):
611
621
"""
612
622
Save and return a list of object instances.
613
623
"""
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
+
614
634
validated_data = [
615
635
dict (list (attrs .items ()) + list (kwargs .items ()))
616
636
for attrs in self .validated_data
0 commit comments