JohnDoee / deluge-client

A very lightweight pure-python Deluge RPC Client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to filter torrents based on non-string fields

jasonlyle88 opened this issue · comments

I am using python 3.7 with deluge-client 1.7.1.

When trying to filter the set of returned torrents via filter_dict parameter, I get an error if I pass a non-string value. However, if I pass a string value for a field that is not a string (int, float, bool), I get no torrents returned. The best example of this is when calling core.get_torrents_status. If I try to pass a filter dict of {'progress': 100} or {'progress': 100.0}, I get the following errors:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/flexget/app/lib/python3.7/site-packages/deluge_client/client.py", line 247, in call
    return self._receive_response(self.deluge_version, self.deluge_protocol_version)
  File "/opt/flexget/app/lib/python3.7/site-packages/deluge_client/client.py", line 226, in _receive_response
    raise exception(exception_msg)
deluge_client.client.TypeError: argument of type 'float' is not iterable
  File "/usr/lib/python2.7/dist-packages/deluge/core/rpcserver.py", line 301, in dispatch
    ret = self.factory.methods[method](*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/deluge/core/core.py", line 461, in get_torrents_status
    torrent_ids = self.filtermanager.filter_torrent_ids(filter_dict)
  File "/usr/lib/python2.7/dist-packages/deluge/core/filtermanager.py", line 172, in filter_torrent_ids
    if field in status and status[field] in values:

(obviously, the line stating deluge_client.client.TypeError: argument of type 'float' is not iterable switches float out for int/bool depending on what is actually passed).

If I switch to {'progress': '100'}, {'progress': '100.0'}, {'progress': "100"}, or {'progress': "100.0"}, then I get nothing back (even though I should have several torrents returned).

As I mentioned bool as well, I tested this with the is_seed property, and I have the same issue with bool types as I do with int/float types.

Filter inputs must be strings OR a list of other types. That's a Deluge thing I don't know why is like that.

https://github.com/deluge-torrent/deluge/blob/deluge-1.3.15/deluge/core/filtermanager.py#L128-L130

Can you try [100] and see if it works, I assume you already checked the datatype of progress variable.

The check code can be seen here where it's shown that Deluge loops over a list of filter items.

https://github.com/deluge-torrent/deluge/blob/deluge-1.3.15/deluge/core/filtermanager.py#L171-L172

That did it. That is so weird that they require that, but it makes it work. I did {"progress": [100]}, {"progress": [100.0]} and {"is_seed": [True]}, {"is_seed": [False]} and they all worked. Thanks for the information. As this is a weird case, this may be worth throwing in the readme or on the wiki page!