Page MenuHomePhabricator

Third-party families cannot be registered in user-config.py
Closed, DuplicatePublic

Description

I was able to work around this issue with help from T234135, but this still seems like a bug. I've created a Github repository to act as a self-contained reproduction of this problem. There's much more information in the readme. Please let me know if you need any more information from me!

Event Timeline

You register family file from app folder, but it is not in app folder?

The Dockerfile changes the directory structure with the line COPY cfg/* /app/. I originally wanted to keep the config files in their own folder, but the simplest solution turned out to be moving them to the working directory. I realize now that it's confusing to change the directory structure in the Dockerfile. I've updated the repository; it should be clearer now.

I'm sorry, but could you post steps to reproduce without docker or unittests? I can't make docker run on my PC (still the same error, none of the solutions online worked), also I still miss any kind of traceback or error message. What do you want to achieve and what is broken?

Okay, I made some detective work to find out, what could be wrong and I got to this traceback:

$ python
Python 3.8.1 (default, Jan 22 2020, 06:38:00) 
[GCC 9.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pywikibot
>>> s=pywikibot.Site()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pavel/pywikibot/pywikibot/tools/__init__.py", line 1790, in wrapper
    return obj(*__args, **__kw)
  File "/home/pavel/pywikibot/pywikibot/__init__.py", line 1242, in Site
    fam = Family.load(fam)
  File "/home/pavel/pywikibot/pywikibot/tools/__init__.py", line 1790, in wrapper
    return obj(*__args, **__kw)
  File "/home/pavel/pywikibot/pywikibot/family.py", line 1008, in load
    raise UnknownFamily('Family %s does not exist' % fam)
pywikibot.exceptions.UnknownFamily: Family projectgorgon does not exist

This seems clear, deprecation wrapper tries to load family before config is fully processed. There is another minor issue, as deprecation wrapper silently pass this error and therefore the rest of config is never loaded (register_family_file in config does not work)

You can avoid this bug by registering family file in your script directly, not in user-config btw

Dvorapa renamed this task from When using pywikibot as a library, third-party families cannot be registered in user-config.py to Third-party families cannot be registered in user-config.py.Feb 19 2020, 12:51 PM

I've added Dockerless instructions and the traceback to the readme. I Dockerized the example to make it entirely self-contained and reproducible, but I didn't realize I was making it harder to access. Sorry about that. And yes, registering the family in the script is my workaround, but I figured this was worth reporting anyway.