nebius/SWE-bench-extra huggingface dataset:
Repository: SparkPost/python-sparkpost

Issue:
Validate recipients as list or dict
We currently don't do any input validation for recipients. It'd be pretty simple to check for list or dict and throw an appropriate exception. This will help avoid some confusion around the error received when a string, for example, is passed.

Comments:

Patch:
diff --git a/sparkpost/transmissions.py b/sparkpost/transmissions.py
index 3586e2f..667b891 100644
--- a/sparkpost/transmissions.py
+++ b/sparkpost/transmissions.py
@@ -4,6 +4,7 @@ import json
 from email.utils import parseaddr
 
 from .base import Resource
+from .exceptions import SparkPostException
 
 
 try:
@@ -137,6 +138,10 @@ class Transmissions(Resource):
         return parsed_address
 
     def _extract_recipients(self, recipients):
+
+        if not (isinstance(recipients, (list, dict))):
+            raise SparkPostException('recipients must be a list or dict')
+
         formatted_recipients = []
         for recip in recipients:
             if isinstance(recip, string_types):


Test patch:
diff --git a/test/test_transmissions.py b/test/test_transmissions.py
index 9847fb2..a5d6ae0 100644
--- a/test/test_transmissions.py
+++ b/test/test_transmissions.py
@@ -9,7 +9,7 @@ import six
 
 from sparkpost import SparkPost
 from sparkpost import Transmissions
-from sparkpost.exceptions import SparkPostAPIException
+from sparkpost.exceptions import SparkPostAPIException, SparkPostException
 
 
 def test_translate_keys_with_list():
@@ -29,6 +29,12 @@ def test_translate_keys_with_recips():
                                      {'address': {'email': 'foobar'}}]
 
 
+def test_exceptions_for_recipients():
+    t = Transmissions('uri', 'key')
+    with pytest.raises(SparkPostException):
+        t._translate_keys(recipients='test')
+
+
 def test_translate_keys_with_unicode_recips():
     t = Transmissions('uri', 'key')
     results = t._translate_keys(recipients=[u'unicode_email@example.com',