From 2a2508e12faeac606d026fb7493bba0cc117cd35 Mon Sep 17 00:00:00 2001 From: w- Date: Tue, 21 Apr 2015 12:06:52 -0700 Subject: [PATCH] incrase 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 if this change is appropriate and not sure what, if any, additional tests to include with this . --- rest_framework/serializers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 7d85894f6..b660a8368 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -986,7 +986,11 @@ class ModelSerializer(Serializer): m2m_data[field_name] = attrs.pop(field_name) # Forward m2m relations - for field in meta.many_to_many + meta.virtual_fields: + if issubclass(meta.many_to_many, tuple): + temp_m2m = list(meta.many_to_many) + else: + temp_m2m = meta.many_to_many + for field in temp_m2m + meta.virtual_fields: if isinstance(field, GenericForeignKey): continue if field.name in attrs: