Repository: Flexget/Flexget

Issue:
Transmission cann't handle two clients when crossmatch
<!---
Before opening an issue, verify:

- Is this a feature request? Post it on https://feathub.com/Flexget/Flexget
- Is this an issue with webui? Make an issue over on https://github.com/Flexget/webui
- Did you recently upgrade? Look at the Change Log and Upgrade Actions to make sure that you don't need to make any changes to your config https://flexget.com/ChangeLog https://flexget.com/UpgradeActions
- Are you running FlexGet as a daemon? Stop it completely and then start it again https://flexget.com/CLI/daemon
- Did you search to see if the issue already exists? https://github.com/Flexget/Flexget/issues
- Did you fill out the issue template as completely as possible?

The issue template is here because it helps to ensure you submitted all the necessary information the first time, and allows us to more quickly review issues. Please fill it out correctly and do not ignore it, no matter how irrelevant you think it may be. Thanks in advance for your help with this!
--->

### Expected behaviour:

<!---
Please don't just say "it doesn't crash" or "it works". Explain what the expected result is.
--->
Client1 + Client2 both purge seeds.

### Actual behaviour:
Client1 purged, but client2 doesn't.
Because teansmission-rpc will remeber the last client.

### Steps to reproduce:
use from_transmission_client2 crossmatch from_transmission_client1(which produce title that want to be purged)

#### Config:
```
  clean.purge_reseed_seeds:
    free_space:
      abort_if: above
      space: 30000
    <<: *from_transmission_reseed #Client2
    crossmatch:
      from: [from_task: purge.finished_seeds]
      fields: [title]
      action: accept
    <<: *purge_transmission_reseed

  purge.finished_seeds:
    limit_new: 2
    <<: *from_transmission #Client1
    imdb_lookup: yes
    sort_by: transmission_date_done
    if:
      - transmission_progress != 100.0: reject
    list_match:
      from:
        - movie_list: symlinked-movies
    <<: *purge_transmission
```
  
#### Log:
<details>
 <summary>(click to expand)</summary>

```
2022-01-28 21:14:26 DEBUG    task          clean.purge_reseed_seeds executing clean.purge_reseed_seeds
2022-01-28 21:14:26 DEBUG    template      clean.purge_reseed_seeds Merging template global into task clean.purge_reseed_seeds
2022-01-28 21:14:26 DEBUG    log_filter    clean.purge_reseed_seeds Log filter added (config: [{'plugin': 'free_space', 'task': 'clean.purge_reseed_seeds'}])
2022-01-28 21:14:26 DEBUG    disable       clean.purge_reseed_seeds Disabled plugins: status, history, seen_info_hash, seen
2022-01-28 21:14:26 DEBUG    transmission  clean.purge_reseed_seeds Connecting to http://192.168.1.102:9092/transmission/
2022-01-28 21:14:26 DEBUG    backlog       clean.purge_reseed_seeds 0 entries purged from backlog
2022-01-28 21:14:26 VERBOSE  details       clean.purge_reseed_seeds Produced 10 entries.
2022-01-28 21:14:26 VERBOSE  from_task     clean.purge_reseed_seeds Running task `purge.finished_seeds` as subtask.
2022-01-28 21:14:26 DEBUG    task          clean.purge_reseed_seeds>purge.finished_seeds executing clean.purge_reseed_seeds>purge.finished_seeds
2022-01-28 21:14:26 DEBUG    template      clean.purge_reseed_seeds>purge.finished_seeds Merging template global into task clean.purge_reseed_seeds>purge.finished_seeds
2022-01-28 21:14:27 DEBUG    log_filter    clean.purge_reseed_seeds>purge.finished_seeds Log filter added (config: [{'plugin': 'free_space', 'task': 'clean.purge_reseed_seeds>purge.finished_seeds'}])
2022-01-28 21:14:27 DEBUG    disable       clean.purge_reseed_seeds>purge.finished_seeds Disabled plugins: history, seen_info_hash, seen
2022-01-28 21:14:27 DEBUG    remember_rej  clean.purge_reseed_seeds>purge.finished_seeds Task config has changed since last run, purging remembered entries.
2022-01-28 21:14:27 DEBUG    transmission  clean.purge_reseed_seeds>purge.finished_seeds Connecting to http://192.168.1.101:9091/transmission/
2022-01-28 21:14:27 DEBUG    backlog       clean.purge_reseed_seeds>purge.finished_seeds 0 entries purged from backlog
2022-01-28 21:14:27 VERBOSE  details       clean.purge_reseed_seeds>purge.finished_seeds Produced 3 entries.
2022-01-28 21:14:27 DEBUG    manipulate    clean.purge_reseed_seeds>purge.finished_seeds field: `title` from_field: `title` field_value: `sprd-790 Kaori Otosaki.mp4`
2022-01-28 21:14:27 DEBUG    manipulate    clean.purge_reseed_seeds>purge.finished_seeds field: `title` from_field: `title` field_value: `sprd-790 Kaori Otosaki.mp4`
2022-01-28 21:14:27 DEBUG    manipulate    clean.purge_reseed_seeds>purge.finished_seeds field `title` after replace: `sprd-790 Kaori Otosaki.mp4`
2022-01-28 21:14:27 DEBUG    manipulate    clean.purge_reseed_seeds>purge.finished_seeds field: `title` from_field: `title` field_value: `Reset.S01.2022.2160p.WEB-DL.H265.DDP-TJUPT`
2022-01-28 21:14:27 DEBUG    manipulate    clean.purge_reseed_seeds>purge.finished_seeds field: `title` from_field: `title` field_value: `Reset.S01.2022.2160p.WEB-DL.H265.DDP-TJUPT`
2022-01-28 21:14:27 DEBUG    manipulate    clean.purge_reseed_seeds>purge.finished_seeds field `title` after replace: `Reset.S01.2022.2160p.WEB-DL.H265.DDP-TJUPT`
2022-01-28 21:14:27 DEBUG    manipulate    clean.purge_reseed_seeds>purge.finished_seeds field: `title` from_field: `title` field_value: `Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai`
2022-01-28 21:14:27 DEBUG    manipulate    clean.purge_reseed_seeds>purge.finished_seeds field: `title` from_field: `title` field_value: `Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai`
2022-01-28 21:14:27 DEBUG    manipulate    clean.purge_reseed_seeds>purge.finished_seeds field `title` after replace: `Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai`
2022-01-28 21:14:27 VERBOSE  manipulate    clean.purge_reseed_seeds>purge.finished_seeds Modified 0 entries.
2022-01-28 21:14:27 DEBUG    sort_by       clean.purge_reseed_seeds>purge.finished_seeds sorting entries by: transmission_date_done
2022-01-28 21:14:27 DEBUG    if            clean.purge_reseed_seeds>purge.finished_seeds sprd-790 Kaori Otosaki.mp4 matched requirement now - transmission_date_done < timedelta(days=2)
2022-01-28 21:14:27 VERBOSE  task          clean.purge_reseed_seeds>purge.finished_seeds REJECTED: `sprd-790 Kaori Otosaki.mp4` by if plugin because matched requirement: now - transmission_date_done < timedelta(days=2)
2022-01-28 21:14:27 DEBUG    if            clean.purge_reseed_seeds>purge.finished_seeds Reset.S01.2022.2160p.WEB-DL.H265.DDP-TJUPT matched requirement now - transmission_date_done < timedelta(days=2)
2022-01-28 21:14:27 VERBOSE  task          clean.purge_reseed_seeds>purge.finished_seeds REJECTED: `Reset.S01.2022.2160p.WEB-DL.H265.DDP-TJUPT` by if plugin because matched requirement: now - transmission_date_done < timedelta(days=2)
2022-01-28 21:14:27 DEBUG    if            clean.purge_reseed_seeds>purge.finished_seeds Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai matched requirement transmission_status == 'stopped'
2022-01-28 21:14:27 VERBOSE  task          clean.purge_reseed_seeds>purge.finished_seeds ACCEPTED: `Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai` by if plugin because matched requirement: transmission_status == 'stopped'
2022-01-28 21:14:27 DEBUG    imdb_lookup   clean.purge_reseed_seeds>purge.finished_seeds lookup for Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai
2022-01-28 21:14:27 DEBUG    imdb.db       clean.purge_reseed_seeds>purge.finished_seeds movie `Eternals` age 1 expires in 7 days
2022-01-28 21:14:27 DEBUG    movie_list    clean.purge_reseed_seeds>purge.finished_seeds trying to match movie based off id imdb_id: tt9032400
2022-01-28 21:14:27 DEBUG    movie_list    clean.purge_reseed_seeds>purge.finished_seeds trying to match movie based of name: Eternals and year: 2021
2022-01-28 21:14:27 VERBOSE  limit_new     clean.purge_reseed_seeds>purge.finished_seeds Allowed Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai ()
2022-01-28 21:14:27 DEBUG    limit_new     clean.purge_reseed_seeds>purge.finished_seeds Rejected: 0 Allowed: 1
2022-01-28 21:14:27 DEBUG    urlrewriter   clean.purge_reseed_seeds>purge.finished_seeds Checking 1 entries
2022-01-28 21:14:27 VERBOSE  details       clean.purge_reseed_seeds>purge.finished_seeds Summary - Accepted: 1 (Rejected: 2 Undecided: 0 Failed: 0)
2022-01-28 21:14:27 DEBUG    transmission  clean.purge_reseed_seeds>purge.finished_seeds Connecting to http://192.168.1.101:9091/transmission/
2022-01-28 21:14:27 DEBUG    transmission  clean.purge_reseed_seeds>purge.finished_seeds Successfully connected to transmission.
2022-01-28 21:14:27 DEBUG    transmission  clean.purge_reseed_seeds>purge.finished_seeds Found Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai already loaded in transmission as Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai
2022-01-28 21:14:27 INFO     transmission  clean.purge_reseed_seeds>purge.finished_seeds purged Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai from transmission
2022-01-28 21:14:27 VERBOSE  list_match    clean.purge_reseed_seeds>purge.finished_seeds removing accepted entries from movie_list - symlinked-movies
2022-01-28 21:14:27 DEBUG    movie_list    clean.purge_reseed_seeds>purge.finished_seeds trying to match movie based off id imdb_id: tt9032400
2022-01-28 21:14:27 DEBUG    movie_list    clean.purge_reseed_seeds>purge.finished_seeds trying to match movie based of name: Eternals and year: 2021
2022-01-28 21:14:27 DEBUG    util.simple_persistence clean.purge_reseed_seeds>purge.finished_seeds Flushing simple persistence for task clean.purge_reseed_seeds>purge.finished_seeds to db.
2022-01-28 21:14:27 DEBUG    util.simple_persistence clean.purge_reseed_seeds>purge.finished_seeds Flushing simple persistence for task None to db.
2022-01-28 21:14:27 VERBOSE  from_task     clean.purge_reseed_seeds Finished running subtask `purge.finished_seeds`.
2022-01-28 21:14:27 VERBOSE  task          clean.purge_reseed_seeds ACCEPTED: `Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai` by crossmatch plugin because intersects with Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai on field(s) title
2022-01-28 21:14:27 VERBOSE  task          clean.purge_reseed_seeds ACCEPTED: `Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai` by crossmatch plugin because intersects with Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai on field(s) title
2022-01-28 21:14:27 VERBOSE  task          clean.purge_reseed_seeds ACCEPTED: `Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai` by crossmatch plugin because intersects with Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai on field(s) title
2022-01-28 21:14:27 DEBUG    urlrewriter   clean.purge_reseed_seeds Checking 3 entries
2022-01-28 21:14:27 VERBOSE  details       clean.purge_reseed_seeds Summary - Accepted: 3 (Rejected: 0 Undecided: 7 Failed: 0)
2022-01-28 21:14:27 WARNING  transmission  clean.purge_reseed_seeds Cannot purge Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai because it is not loaded in transmission.
2022-01-28 21:14:27 WARNING  transmission  clean.purge_reseed_seeds Cannot purge Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai because it is not loaded in transmission.
2022-01-28 21:14:27 WARNING  transmission  clean.purge_reseed_seeds Cannot purge Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai because it is not loaded in transmission.
2022-01-28 21:14:27 DEBUG    util.simple_persistence clean.purge_reseed_seeds Flushing simple persistence for task clean.purge_reseed_seeds to db.
2022-01-28 21:14:27 DEBUG    util.simple_persistence clean.purge_reseed_seeds Flushing simple persistence for task None to db.
```
</details>

### Additional information:

- FlexGet version: 3.2.13
- Python version: 
- Installation method: docker/wiserain/flexget
- Using daemon (yes/no): yes
- OS and version:
- Link to crash log:

<!---
In config and debug/crash logs, remember to redact any personal or sensitive information such as passwords, API keys, private URLs and so on.

Please verify that the following data is present before submitting your issue:

- Link to a paste service or paste above the relevant config (preferably full config, including templates if present). Please make sure the paste does not expire, if possible.
- Link to a paste service or paste above debug-level logs of the relevant task/s (use `flexget -L debug execute --tasks <Task_name>`).
- FlexGet version (use `flexget -V` to get it).
- Full Python version, for example `2.7.11` (use `python -V` to get it). 
- Installation method (pip, git install, etc).
- Whether or not you're running FlexGet as a daemon.
- OS and version.
- Attach crash log if one was generated, in addition to the debug-level log. It can be found in the directory with your config file.
--->



Discussion:
This example is crazy and not a lot of people with 2 transmission instances to try to replicate this :rofl:

I need a little more info to understand the problem.

- I see that your from task returns one accepted entry "Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai" and it removes it from trasmission.
- Then it crossmatches with the other transmission instance and finds 3 torrents with the same name????
- Then it fails to remove because it can't find it in transmission.

So:
- Is the first correct? The from task is correct?
- Do you have 3 entry with the same name?
- It faills to remove, I assume that this is the problem... You actually have the entry in transmission. You should have, if crossmatch and f was able to map them.


Yes, you are right.
Let me write some details.

Client 1 (which used for download) 

With 1x 
"Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai"

Client 2 (which used for cross-reseed) 
with 3 x
"Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai"

the task "from_task" behave correct.
the torrent will be purge. 
"Eternals.2021.BluRay.1080p.DTS-HD.MA5.1.x265.10bit-BeiTai"


but the task "cross_match" will fail. 
because the task goes the remembered transmission_client_1 to match the 3 titles, which it should go transmission_client_2 to match the 3 titles. Then it failed. 


I suppose the point is once transmission-rpc connected, it will not disconnected for another transmission instance. 
I can actually see the problem! This is a reccuring problem with the from_task! Let me see if I can do something about it!
I solved this issue, please confirm that it's working
Many thanks! 
But I don't know how to test it before you release it. I will test it as soon as you release it. 

Resolving patch:
diff --git a/flexget/plugins/clients/transmission.py b/flexget/plugins/clients/transmission.py
--- a/flexget/plugins/clients/transmission.py
+++ b/flexget/plugins/clients/transmission.py
@@ -30,10 +30,6 @@
 
 
 class TransmissionBase:
-    def __init__(self):
-        self.client = None
-        self.opener = None
-
     def prepare_config(self, config):
         if isinstance(config, bool):
             config = {'enabled': config}
@@ -53,7 +49,7 @@ def prepare_config(self, config):
                 logger.error('netrc: {}, file: {}, line: {}', e.msg, e.filename, e.lineno)
         return config
 
-    def create_rpc_client(self, config):
+    def create_rpc_client(self, config) -> 'transmissionrpc.Client':
         user, password = config.get('username'), config.get('password')
         urlo = urlparse(config['host'])
 
@@ -146,13 +142,12 @@ def on_task_start(self, task, config):
 
         # Mark rpc client for garbage collector so every task can start
         # a fresh new according its own config - fix to bug #2804
-        self.client = None
         config = self.prepare_config(config)
         if config['enabled']:
             if task.options.test:
                 logger.info('Trying to connect to transmission...')
-                self.client = self.create_rpc_client(config)
-                if self.client:
+                client = self.create_rpc_client(config)
+                if client:
                     logger.info('Successfully connected to transmission.')
                 else:
                     logger.error('It looks like there was a problem connecting to transmission.')
@@ -188,13 +183,12 @@ def on_task_input(self, task, config):
         if not config['enabled']:
             return
 
-        if not self.client:
-            self.client = self.create_rpc_client(config)
+        client = self.create_rpc_client(config)
         entries = []
 
-        session = self.client.get_session()
+        session = client.get_session()
 
-        for torrent in self.client.get_torrents():
+        for torrent in client.get_torrents():
             seed_ratio_ok, idle_limit_ok = self.check_seed_limits(torrent, session)
             if config['only_complete'] and not (
                 seed_ratio_ok and idle_limit_ok and torrent.progress == 100
@@ -370,13 +364,12 @@ def on_task_output(self, task, config):
         # Do not run if there is nothing to do
         if not task.accepted:
             return
-        if self.client is None:
-            self.client = self.create_rpc_client(config)
-            if self.client:
-                logger.debug('Successfully connected to transmission.')
-            else:
-                raise plugin.PluginError("Couldn't connect to transmission.")
-        session_torrents = self.client.get_torrents()
+        client = self.create_rpc_client(config)
+        if client:
+            logger.debug('Successfully connected to transmission.')
+        else:
+            raise plugin.PluginError("Couldn't connect to transmission.")
+        session_torrents = client.get_torrents()
         for entry in task.accepted:
             if task.options.test:
                 logger.info('Would {} {} in transmission.', config['action'], entry['title'])
@@ -423,11 +416,11 @@ def on_task_output(self, task, config):
                     if downloaded:
                         with open(entry['file'], 'rb') as f:
                             filedump = base64.b64encode(f.read()).decode('utf-8')
-                        torrent_info = self.client.add_torrent(filedump, 30, **options['add'])
+                        torrent_info = client.add_torrent(filedump, 30, **options['add'])
                     else:
                         if options['post'].get('magnetization_timeout', 0) > 0:
                             options['add']['paused'] = False
-                        torrent_info = self.client.add_torrent(
+                        torrent_info = client.add_torrent(
                             entry['url'], timeout=30, **options['add']
                         )
                 except TransmissionError as e:
@@ -441,7 +434,7 @@ def on_task_output(self, task, config):
                     continue
                 logger.info('"{}" torrent added to transmission', entry['title'])
                 # The info returned by the add call is incomplete, refresh it
-                torrent_info = self.client.get_torrent(torrent_info.id)
+                torrent_info = client.get_torrent(torrent_info.id)
             else:
                 # Torrent already loaded in transmission
                 if options['add'].get('download_dir'):
@@ -454,9 +447,7 @@ def on_task_output(self, task, config):
                     # In such case this will kick transmission to really move data.
                     # If data is already located at new location then transmission just ignore
                     # this command.
-                    self.client.move_torrent_data(
-                        torrent_info.id, options['add']['download_dir'], 120
-                    )
+                    client.move_torrent_data(torrent_info.id, options['add']['download_dir'], 120)
 
             try:
                 total_size = torrent_info.totalSize
@@ -467,7 +458,7 @@ def on_task_output(self, task, config):
                 skip_files = options['post'].get('skip_files')
                 # We need to index the files if any of the following are defined
                 if find_main_file or skip_files:
-                    file_list = self.client.get_files(torrent_info.id)[torrent_info.id]
+                    file_list = client.get_files(torrent_info.id)[torrent_info.id]
 
                     if options['post'].get('magnetization_timeout', 0) > 0 and not file_list:
                         logger.debug(
@@ -477,9 +468,9 @@ def on_task_output(self, task, config):
                         )
                         for _ in range(options['post']['magnetization_timeout']):
                             sleep(1)
-                            file_list = self.client.get_files(torrent_info.id)[torrent_info.id]
+                            file_list = client.get_files(torrent_info.id)[torrent_info.id]
                             if file_list:
-                                total_size = self.client.get_torrent(
+                                total_size = client.get_torrent(
                                     torrent_info.id, ['id', 'totalSize']
                                 ).totalSize
                                 break
@@ -542,7 +533,7 @@ def on_task_output(self, task, config):
                     # If we have a main file and want to rename it and associated files
                     if 'content_filename' in options['post'] and main_id is not None:
                         if 'download_dir' not in options['add']:
-                            download_dir = self.client.get_session().download_dir
+                            download_dir = client.get_session().download_dir
                         else:
                             download_dir = options['add']['download_dir']
 
@@ -574,7 +565,7 @@ def on_task_output(self, task, config):
                             # change to below when set_files will allow setting name, more efficient to have one call
                             # fl[index]['name'] = os.path.basename(pathscrub(filename + file_ext).encode('utf-8'))
                             try:
-                                self.client.rename_torrent_path(
+                                client.rename_torrent_path(
                                     torrent_info.id,
                                     file_list[file_id].name,
                                     os.path.basename(str(pathscrub(filename + file_ext))),
@@ -618,9 +609,9 @@ def on_task_output(self, task, config):
 
                 # Set any changed file properties
                 if list(options['change'].keys()):
-                    self.client.change_torrent(torrent_info.id, 30, **options['change'])
+                    client.change_torrent(torrent_info.id, 30, **options['change'])
 
-                start_torrent = partial(self.client.start_torrent, [torrent_info.id])
+                start_torrent = partial(client.start_torrent, [torrent_info.id])
 
                 if config['action'] == 'add':
                     # if add_paused was defined and set to False start the torrent;
@@ -628,19 +619,19 @@ def on_task_output(self, task, config):
                     start_paused = (
                         options['post']['paused']
                         if 'paused' in options['post']
-                        else not self.client.get_session().start_added_torrents
+                        else not client.get_session().start_added_torrents
                     )
                     if start_paused:
-                        self.client.stop_torrent(torrent_info.id)
+                        client.stop_torrent(torrent_info.id)
                     else:
-                        self.client.start_torrent(torrent_info.id)
+                        client.start_torrent(torrent_info.id)
                 elif config['action'] in ('remove', 'purge'):
-                    self.client.remove_torrent(
+                    client.remove_torrent(
                         [torrent_info.id], delete_data=config['action'] == 'purge'
                     )
                     logger.info('{}d {} from transmission', config['action'], torrent_info.name)
                 elif config['action'] == 'pause':
-                    self.client.stop_torrent([torrent_info.id])
+                    client.stop_torrent([torrent_info.id])
                     logger.info('paused {} in transmission', torrent_info.name)
                 elif config['action'] == 'resume':
                     start_torrent()
@@ -835,8 +826,7 @@ def on_task_exit(self, task, config):
         config = self.prepare_config(config)
         if not config['enabled'] or task.options.learn:
             return
-        if not self.client:
-            self.client = self.create_rpc_client(config)
+        client = self.create_rpc_client(config)
         tracker_re = re.compile(config['tracker'], re.IGNORECASE) if 'tracker' in config else None
         preserve_tracker_re = (
             re.compile(config['preserve_tracker'], re.IGNORECASE)
@@ -844,10 +834,10 @@ def on_task_exit(self, task, config):
             else None
         )
 
-        session = self.client.get_session()
+        session = client.get_session()
 
         remove_ids = []
-        for torrent in self.client.get_torrents():
+        for torrent in client.get_torrents():
             logger.verbose(
                 'Torrent "{}": status: "{}" - ratio: {} - date added: {}',
                 torrent.name,
@@ -890,7 +880,7 @@ def on_task_exit(self, task, config):
             logger.info('Removing finished torrent `{}` from transmission', torrent.name)
             remove_ids.append(torrent.id)
         if remove_ids:
-            self.client.remove_torrent(remove_ids, config.get('delete_files'))
+            client.remove_torrent(remove_ids, config.get('delete_files'))
 
 
 @event('plugin.register')


Test patch: