Repository: Azure/msrest-for-python

Issue:
Should refuse a string as a valid list of string
Ends up in the portal as ['a','b','c'] if we use `Model('abc')` instead of `Model(['abc'])`. Should fail, accepting a string for a list of string is likely an error and not a feature.

See https://github.com/Azure/azure-sdk-for-python/issues/1376#issuecomment-323409463

Discussion:

Patch:
diff --git a/msrest/serialization.py b/msrest/serialization.py
index cc03063..61e811f 100644
--- a/msrest/serialization.py
+++ b/msrest/serialization.py
@@ -623,6 +623,8 @@ class Serializer(object):
          in the iterable into a combined string. Default is 'None'.
         :rtype: list, str
         """
+        if isinstance(data, str):
+            raise SerializationError("Refuse str type as a valid iter type.")
         serialized = []
         for d in data:
             try:


Test patch:
diff --git a/tests/test_serialization.py b/tests/test_serialization.py
index 4d6a80a..39f2878 100644
--- a/tests/test_serialization.py
+++ b/tests/test_serialization.py
@@ -736,6 +736,10 @@ class TestRuntimeSerialized(unittest.TestCase):
         b = self.s.serialize_iter([], 'int')
         self.assertEqual(b, [])
 
+    def test_serialize_str_as_iter(self):
+        with self.assertRaises(SerializationError):
+            self.s.serialize_iter("I am a string", 'str')
+
     def test_serialize_json_obj(self):
 
         class ComplexId(Model):