diff options
author | Claude Paroz <claude@2xlibre.net> | 2012-08-08 17:59:31 +0200 |
---|---|---|
committer | Claude Paroz <claude@2xlibre.net> | 2012-08-08 18:02:25 +0200 |
commit | db729266d6feb3b4b4519bd789c4693b9aac00d1 (patch) | |
tree | 347dcf5c5e077d003ce2d6f62d8614182794b63d /django/core/serializers/python.py | |
parent | 0955d16a165e9da2f69813cc9983fd10dddbfa62 (diff) | |
download | django-db729266d6feb3b4b4519bd789c4693b9aac00d1.tar.gz |
[py3] Fixed 'iterable but non string' detection
In Python 3, the str type has an __iter__ attribute. Therefore, the
presence of an __iter__ attribute is not sufficient to distinguish
'standard' iterables (list, tuple) from strings.
Diffstat (limited to 'django/core/serializers/python.py')
-rw-r--r-- | django/core/serializers/python.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index 348ff1dada..a1fff6f9bb 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -98,7 +98,7 @@ def Deserializer(object_list, **options): if field.rel and isinstance(field.rel, models.ManyToManyRel): if hasattr(field.rel.to._default_manager, 'get_by_natural_key'): def m2m_convert(value): - if hasattr(value, '__iter__'): + if hasattr(value, '__iter__') and not isinstance(value, six.text_type): return field.rel.to._default_manager.db_manager(db).get_by_natural_key(*value).pk else: return smart_text(field.rel.to._meta.pk.to_python(value)) @@ -110,7 +110,7 @@ def Deserializer(object_list, **options): elif field.rel and isinstance(field.rel, models.ManyToOneRel): if field_value is not None: if hasattr(field.rel.to._default_manager, 'get_by_natural_key'): - if hasattr(field_value, '__iter__'): + if hasattr(field_value, '__iter__') and not isinstance(field_value, six.text_type): obj = field.rel.to._default_manager.db_manager(db).get_by_natural_key(*field_value) value = getattr(obj, field.rel.field_name) # If this is a natural foreign key to an object that |