trim21 / transmission-rpc

https://transmission-rpc.readthedocs.io/en/stable/
MIT License
147 stars 34 forks source link

Cannot get files of a torrent without unnecessary priorities and wanted fields #455

Open cheeseandcereal opened 4 months ago

cheeseandcereal commented 4 months ago

Description

Currently, it is impossible to get files of a torrent (with the .get_files() interface) unless you fetch the priorities and wanted fields.

This is due to trying to directly reference these fields here: https://github.com/trim21/transmission-rpc/blob/57c064f6b740b67be1ed7c5afad5ce18476616f4/transmission_rpc/torrent.py#L436-L437

It currently returns a key error if you try to use this:

    priorities = self.fields["priorities"]
                 ~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'priorities'

This doesn't really seem necessary and forces fetching these fields onto users for use-cases that may not need them.

I would propose updating this function or providing an alternative interface to get the files of a Torrent class

(as a side note, why are getting files a function interface while everything else on the class is a property? It seems a bit weird/inconsistent)

cheeseandcereal commented 4 months ago

(As a note to others who find this issue before it's fixed)

A hacky workaround to this without actually fetching the additional fields is to just manually set the internal field state of the torrent yourself before calling .get_files() - i.e.:

torrent.fields["priorities"] = [0] * len(torrent.fields["files"])
torrent.fields["wanted"] = [True] * len(torrent.fields["files"])
# get_files() should now work
torrent.get_files()
trim21 commented 4 months ago

ref https://github.com/trim21/transmission-rpc/pull/446

cheeseandcereal commented 4 months ago

A bit weird to close this issue because it's definitely not fixed by the mention of an unmerged PR. Unless you're saying you won't fix?

Should probably separate #446 out, or at least address separately since there's 2 different issues:

  1. Trying to call .get_files() if the files field wasn't fetched should return an error (not what I'm talking about with this issue at all)
  2. Trying to call .get_files() if the priorities or wanted fields aren't fetched should not fail
trim21 commented 4 months ago

2 will be fixed in PR #446

https://github.com/trim21/transmission-rpc/pull/446/files#diff-7e219a90319d2978f745b3b3f979d03f5796aea5cd4f89e5219aa10155513a7cR435

cheeseandcereal commented 4 months ago

Shouldn't this issue remain open until at least it's merged then?

trim21 commented 4 months ago

Yes, both your suggestions on splitting PR and keep issue open sounds reasonable to me. But I'm don't want to spend time on that PR just split it into 2 PR and resolve conflicts when I plan to merge it, so I'll just only re-open this issue.

cheeseandcereal commented 4 months ago

Yeah sounds good. It's just helpful to track this as an open issue. I appreciate it!

trim21 commented 4 months ago

for tracking, I want to avoid unnecessary breaking change so I will merge PR and make new release when new transmission version is released.

trim21 commented 4 months ago

you can use pip to install zip of PR if you need it now.