Repository: Kinto/kinto-http.py

Issue:
json encoding of querystring parameters fails
For instance:

/v1/buckets/bid/collections/cid/records?in_id=["be503c41-3aa6-42e1-9214-0d00ee0ce9ac","51f65e45-b17c-4dc1-970f-1da8f219824f","b4bb1714-cfe3-4cde-9903-66c47b4ce2f2"]&_sort=-published_date&max_published_date="2018-11-12T15:52:00"&language=fr&_limit=100

Doesn't work while:

/v1/buckets/bid/collections/cid/records?in_id=be503c41-3aa6-42e1-9214-0d00ee0ce9ac,51f65e45-b17c-4dc1-970f-1da8f219824f,b4bb1714-cfe3-4cde-9903-66c47b4ce2f2&_sort=-published_date&max_published_date=%222018-11-12T15:52:00%22&language=fr&_limit=100

Does.

Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index f7b1b02..ccff6d3 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -4,10 +4,12 @@ CHANGELOG
 This document describes changes between each past release.
 
 
-10.2.0 (unreleased)
+10.1.1 (unreleased)
 ===================
 
-- Nothing changed yet.
+**Bug fixes**
+
+- Fix JSON support for `in_` and `exclude_`. (#188)
 
 
 10.1.0 (2018-11-05)
diff --git a/kinto_http/session.py b/kinto_http/session.py
index f516a29..aa2ccef 100644
--- a/kinto_http/session.py
+++ b/kinto_http/session.py
@@ -73,7 +73,15 @@ class Session(object):
             kwargs['headers'] = dict()
 
         if kwargs.get('params') is not None:
-            kwargs['params'] = {k: json.dumps(v).strip('"') for k, v in kwargs["params"].items()}
+            params = dict()
+            for key, value in kwargs["params"].items():
+                if key.startswith('in_') or key.startswith('exclude_'):
+                    params[key] = ','.join(value)
+                elif isinstance(value, str):
+                    params[key] = value
+                else:
+                    params[key] = json.dumps(value)
+            kwargs['params'] = params
 
         if not isinstance(kwargs['headers'], dict):
             raise TypeError("headers must be a dict (got {})".format(kwargs['headers']))


Test patch:
diff --git a/kinto_http/tests/test_session.py b/kinto_http/tests/test_session.py
index b3cec55..4492f8d 100644
--- a/kinto_http/tests/test_session.py
+++ b/kinto_http/tests/test_session.py
@@ -241,13 +241,17 @@ class SessionJSONTest(unittest.TestCase):
                                  _sort="-published_date",
                                  is_published=True,
                                  price=12,
-                                 contains_id=["toto", "tata"]))
+                                 contains_id=["toto", "tata"],
+                                 in_id=["toto", "tata"],
+                                 exclude_id=["titi", "tutu"]))
         self.requests_mock.request.assert_called_with(
             'get', 'https://example.org/v1/buckets/buck/collections/coll/records', params={
-                "_sort": "-published_date",
+                "_sort": '-published_date',
                 "is_published": "true",
                 "price": "12",
-                "contains_id": '["toto", "tata"]'
+                "contains_id": '["toto", "tata"]',
+                "in_id": 'toto,tata',
+                "exclude_id": 'titi,tutu'
             }, headers=self.requests_mock.request.headers)