Repository: sunpy/sunpy

Issue:
Slicing a JSOC UnifiedResponse object causes Fido.fetch to fail
```python
tstart = '2011/06/07 06:32:45'
tend = '2011/06/07 06:33:15'                                                                                                                                                                 

res = Fido.search(a.jsoc.Time(tstart, tend), a.jsoc.Series('hmi.M_45s'))

Fido.fetch(res[0,0])
```
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-488027c4a327> in <module>
----> 1 Fido.fetch(res[0,0])

~/Git/sunpy/sunpy/net/fido_factory.py in fetch(self, *query_results, **kwargs)
    360         for query_result in query_results:
    361             for block in query_result.responses:
--> 362                 reslist.append(block.client.fetch(block, **kwargs))
    363 
    364         results = DownloadResponse(reslist)

~/Git/sunpy/sunpy/net/jsoc/jsoc.py in fetch(self, jsoc_response, path, overwrite, progress, max_conn, downloader, sleep)
    532 
    533         # Make staging request to JSOC
--> 534         responses = self.request_data(jsoc_response)
    535         # Make response iterable
    536         if not isiterable(responses):

~/Git/sunpy/sunpy/net/jsoc/jsoc.py in request_data(self, jsoc_response, **kwargs)
    428         requests = []
    429         self.query_args = jsoc_response.query_args
--> 430         for block in jsoc_response.query_args:
    431 
    432             ds = self._make_recordset(**block)

TypeError: 'NoneType' object is not iterable
```                                                                             


Discussion:
Hi, 

I cannot reproduce, exactly, the bug. 

I try this, but the error is different, we are talking about the same problem?

```
>>> import sunpy.map
>>> from sunpy.net import Fido
>>> from sunpy.net import jsoc
>>> tstart = '2011/06/07 06:32:45'
>>> tend = '2011/06/07 06:33:15'
>>> res = Fido.search(a.jsoc.Time(tstart, tend), a.jsoc.Series('hmi.M_45s'))
>>> Fido.fetch(res[0,0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/eamanu/dev/sunpy/sunpy/net/fido_factory.py", line 362, in fetch
    reslist.append(block.client.fetch(block, **kwargs))
  File "/home/eamanu/dev/sunpy/sunpy/net/jsoc/jsoc.py", line 534, in fetch
    responses = self.request_data(jsoc_response)
  File "/home/eamanu/dev/sunpy/sunpy/net/jsoc/jsoc.py", line 430, in request_data
    for block in jsoc_response.query_args:
TypeError: 'NoneType' object is not iterable

```
Hi @eamanu, the error is the same. The difference is how IPython displays the traceback compared to the normal Python interpreter. 
Ok thanks!

Resolving patch:
diff --git a/sunpy/net/jsoc/jsoc.py b/sunpy/net/jsoc/jsoc.py
--- a/sunpy/net/jsoc/jsoc.py
+++ b/sunpy/net/jsoc/jsoc.py
@@ -40,8 +40,8 @@ def __init__(self, table=None, client=None):
         """
         super().__init__()
         self.table = table or astropy.table.QTable()
-        self.query_args = None
-        self.requests = None
+        self.query_args = getattr(table, 'query_args', None)
+        self.requests = getattr(table, 'requests', None)
         self._client = client
 
     @property
@@ -63,7 +63,17 @@ def __len__(self):
             return len(self.table)
 
     def __getitem__(self, item):
-        return type(self)(self.table[item])
+        if isinstance(item, int):
+            item = slice(item, item + 1)
+        ret = type(self)(self.table[item])
+        ret.query_args = self.query_args
+        ret.requests = self.requests
+        ret.client = self._client
+
+        warnings.warn("Downloading of sliced JSOC results is not supported. "
+                      "All the files present in the original response will be downloaded.",
+                      SunpyUserWarning)
+        return ret
 
     def __iter__(self):
         return (t for t in [self])
@@ -340,7 +350,6 @@ def search(self, *query, **kwargs):
             # Update blocks with deep copy of iargs because in _make_recordset we use .pop() on element from iargs
             blocks.append(copy.deepcopy(iargs))
             return_results.append(self._lookup_records(iargs))
-
         return_results.query_args = blocks
         return return_results
 


Test patch:
diff --git a/sunpy/net/tests/test_fido.py b/sunpy/net/tests/test_fido.py
--- a/sunpy/net/tests/test_fido.py
+++ b/sunpy/net/tests/test_fido.py
@@ -467,3 +467,16 @@ def test_fido_no_time(mocker):
     Fido.search(a.jsoc.Series("test"))
 
     jsoc_mock.assert_called_once()
+
+@pytest.mark.remote_data
+def test_slice_jsoc():
+    tstart = '2011/06/07 06:32:45'
+    tend = '2011/06/07 06:33:15'
+    res = Fido.search(a.Time(tstart, tend), a.jsoc.Series('hmi.M_45s'),
+                      a.jsoc.Notify('jsoc@cadair.com'))
+
+    with pytest.warns(SunpyUserWarning):
+        Fido.fetch(res[0, 0])
+
+    with pytest.warns(SunpyUserWarning) as record:
+        Fido.fetch(res[0, 0:1])