Skip to content

Commit ee109c4

Browse files
committed
increase serializer compatibility to django 1.8
i ran into this issue when using v2.4 with django v1.8. (i didn't previously read it isn't supported) It's not in the release notes but django.db.model.Options many_to_many() now returns an ImmutableList which is really just a tuple with a bunch of warnings and hooks on it. if we don't make this typecast change we get the following error TypeError: can only concatenate tuple (not "list") to tuple I'm not sure if this change is appropriate and not sure what, if any, additional tests to include with this . I attempted to test this but must be doing something wrong. Every test fails when trying to use cursor. most of the errors I get are Failed: Database access not allowed, use the "django_db" mark to enable i followed the instructions here. https://github.com/tomchristie/django-rest-framework/blob/version-2.4.x/CONTRIBUTING.md
1 parent 601b224 commit ee109c4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rest_framework/serializers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,11 @@ def restore_object(self, attrs, instance=None):
986986
m2m_data[field_name] = attrs.pop(field_name)
987987

988988
# Forward m2m relations
989-
for field in meta.many_to_many + meta.virtual_fields:
989+
if issubclass(meta.many_to_many.__class__, tuple):
990+
temp_m2m = list(meta.many_to_many)
991+
else:
992+
temp_m2m = meta.many_to_many
993+
for field in temp_m2m + meta.virtual_fields:
990994
if isinstance(field, GenericForeignKey):
991995
continue
992996
if field.name in attrs:

0 commit comments

Comments
 (0)