splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

None returned in _load_atom_entries

Open missing1984 opened this issue 11 years ago • 4 comments

SDK 1.3.1 client.py

when totalResults = 0, a empty array should be returned.. but

# Load an array of atom entries from the body of the given response
def _load_atom_entries(response):
    r = _load_atom(response)
    if 'feed' in r:
        # Need this to handle a random case in the REST API
        if r.feed.get('totalResults') == 0:   <<-- it's actually a string "0" instead of number 0
            return []
        entries = r.feed.get('entry', None)
        if entries is None: return None
        return entries if isinstance(entries, list) else [entries]
    # Unlike most other endpoints, the jobs endpoint does not return
    # its state wrapped in another element, but at the top level.
    # For example, in XML, it returns <entry>...</entry> instead of
    # <feed><entry>...</entry></feed>.
    else:
        entries = r.get('entry', None)
        if entries is None: return None
        return entries if isinstance(entries, list) else [entries]

missing1984 avatar Sep 15 '15 02:09 missing1984

And in some cases, r.feed.get('totalResults') returns a None.

yuanstrong avatar Sep 15 '15 02:09 yuanstrong

Thanks for the bug report! I've sent you both an email, we're busy getting ready for .Conf next week but we can look at fixing this after .Conf.

I'm thinking the following change seems reasonable (of course we'll need some tests):

- if r.feed.get('totalResults') == 0:
+ if r.feed.get('totalResults') in [0, '0', None]:

shakeelmohamed avatar Sep 15 '15 04:09 shakeelmohamed

Hi folks,

I've made the following change with 27554e5796228c64c6a5d0f8dd859b3535f242c9 in develop. If the None case is still an issue, we'll address it in a future release.

-        if r.feed.get('totalResults') == 0:
+        if r.feed.get('totalResults') in [0, '0']:

shakeelmohamed avatar Sep 30 '15 06:09 shakeelmohamed

We've just released v1.5.0 which should address the '0' case.

shakeelmohamed avatar Oct 02 '15 00:10 shakeelmohamed