Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML-RPC ServerProxy in global trips up job loading #1931

Closed
dgw opened this issue Aug 29, 2020 · 1 comment
Closed

XML-RPC ServerProxy in global trips up job loading #1931

dgw opened this issue Aug 29, 2020 · 1 comment
Labels
Bug Things to squish; generally used for issues Duplicate

Comments

@dgw
Copy link
Member

dgw commented Aug 29, 2020

Description

At least one type of global variable that a plugin might reasonably want to keep around (to reduce overhead from constructing a new object every time a command is called) can cause a loading error.

Reproduction steps

Create a plugin file containing a global ServerProxy like this:

import xmlrpc.client

PYPI_XMLRPC_CLIENT = xmlrpc.client.ServerProxy('https://pypi.org/pypi')

Sopel will fail to load the plugin with a cryptic TypeError pointing at its own plugin system internals (see "Logs" section below).

Expected behavior

Sopel loads the plugin with no error, of course.

Logs

[2020-08-29 07:13:57,746] sopel.bot            ERROR    - Error in globalproxy setup: '_Method' object is not iterable
Traceback (most recent call last):
  File "/mnt/c/Users/dgw/github/sopel/sopel/bot.py", line 307, in setup_plugins
    plugin.register(self)
  File "/mnt/c/Users/dgw/github/sopel/sopel/plugins/handlers.py", line 276, in register
    bot.add_plugin(self, *relevant_parts)
  File "/mnt/c/Users/dgw/github/sopel/sopel/bot.py", line 394, in add_plugin
    self.register_jobs(jobs)
  File "/mnt/c/Users/dgw/github/sopel/sopel/bot.py", line 554, in register_jobs
    job = sopel.tools.jobs.Job.from_callable(self.settings, func)
  File "/mnt/c/Users/dgw/github/sopel/sopel/tools/jobs.py", line 290, in from_callable
    set(handler.interval),
TypeError: '_Method' object is not iterable

I think I traced it back to clean_module() returning the ServerProxy object as a job, erroneously:

> /mnt/c/Users/dgw/github/sopel/sopel/loader.py(248)clean_module()->([<function pyp...x7fca513e6a60>], [<ServerProxy ...pypi.org/pypi>], [], [<function pyp...x7fca513e69d8>])
-> return callables, jobs, shutdowns, urls
(Pdb) jobs
[<ServerProxy for pypi.org/pypi>]

Environment

  • Sopel .version: 7.1.0-dev (master branch @ 5525ed2)
  • Sopel installed via: source
  • Python version: 3.6.9
  • Operating system: Ubuntu 18.04 (in WSL 1)

Notes

It seems that a ServerProxy is callable, for some reason (I haven't figured out what is supposed to be retrievable that way; I've only managed to get a lot of AttributeErrors)—and has an (undocumented?) interval attribute that contains some xmlrpc.client._Method (internal class) instance, obviously conflicting with the criteria Sopel uses to figure out if something it found in a module is a job.

It might be time time to add some sanity checks for the attributes Sopel uses when loading plugins, and ignore callables with invalid types. Like, the obvious solution here is to skip returning any callable as a job from clean_module() if it has an interval attribute that isn't a list (optional: of ints).

Opening with no milestone: Not yet clear to me that this is important enough to spend time on for 7.1.

@dgw dgw added the Bug Things to squish; generally used for issues label Aug 29, 2020
@dgw
Copy link
Member Author

dgw commented Aug 29, 2020

Heh, I basically duplicated #859 with a more specific writeup and a more esoteric cause. Oops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Things to squish; generally used for issues Duplicate
Projects
None yet
Development

No branches or pull requests

1 participant