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

"Override settings from command line" feature errors when no overrides given #2789

Closed
2 tasks done
jwodder opened this issue Aug 12, 2020 · 6 comments
Closed
2 tasks done
Labels

Comments

@jwodder
Copy link
Contributor

jwodder commented Aug 12, 2020

Issue

After this commit was made, trying to build with the latest development version of Pelican errors out. Running pelican -s pelicanconf.py --debug outputs the following:

DEBUG: Pelican version: 4.2.0
DEBUG: Python version: 3.8.3 
CRITICAL: 'NoneType' object has no attribute 'items'
Traceback (most recent call last):
  File "/Users/jwodder/work/dev/kbits/.nox/build/bin/pelican", line 8, in <module>  
    sys.exit(main())
  File "/Users/jwodder/work/dev/kbits/.nox/build/lib/python3.8/site-packages/pelican/__init__.py", line 486, in main
    pelican, settings = get_instance(args)
  File "/Users/jwodder/work/dev/kbits/.nox/build/lib/python3.8/site-packages/pelican/__init__.py", line 395, in get_instance
    settings = read_settings(config_file, override=get_config(args))
  File "/Users/jwodder/work/dev/kbits/.nox/build/lib/python3.8/site-packages/pelican/__init__.py", line 383, in get_config
    config.update(coerce_overrides(args.overrides))
  File "/Users/jwodder/work/dev/kbits/.nox/build/lib/python3.8/site-packages/pelican/settings.py", line 667, in coerce_overrides
    for k, v in overrides.items():
AttributeError: 'NoneType' object has no attribute 'items'

I believe the problem is that args.overrides is None when no --extra-settings arguments are given on the command line. Attempting to test this theory by adding --extra-settings AUTHOR=Me made pelican fail with a different error:

DEBUG: Pelican version: 4.2.0
DEBUG: Python version: 3.8.3
CRITICAL: 'AUTHOR'
Traceback (most recent call last):
  File "/Users/jwodder/work/dev/kbits/.nox/build/bin/pelican", line 8, in <module>
    sys.exit(main())
  File "/Users/jwodder/work/dev/kbits/.nox/build/lib/python3.8/site-packages/pelican/__init__.py", line 486, in main
    pelican, settings = get_instance(args)
  File "/Users/jwodder/work/dev/kbits/.nox/build/lib/python3.8/site-packages/pelican/__init__.py", line 395, in get_instance
    settings = read_settings(config_file, override=get_config(args))
  File "/Users/jwodder/work/dev/kbits/.nox/build/lib/python3.8/site-packages/pelican/__init__.py", line 383, in get_config
    config.update(coerce_overrides(args.overrides))
  File "/Users/jwodder/work/dev/kbits/.nox/build/lib/python3.8/site-packages/pelican/settings.py", line 671, in coerce_overrides
    setting_type = type(DEFAULT_CONFIG[k])
KeyError: 'AUTHOR'
@jwodder jwodder added the bug label Aug 12, 2020
@justinmayer
Copy link
Member

@sabaini : Any thoughts on this?

@avaris
Copy link
Member

avaris commented Aug 12, 2020

My bad. Missed some obvious issues in the review. After a quick look, following might be enough to fix. Here:

pelican/pelican/settings.py

Lines 664 to 665 in 74692a3

def coerce_overrides(overrides):
coerced = {}

this addition

def coerce_overrides(overrides):
    if overrides is None:
        return {}
    coerced = {}

And this:

if k not in overrides:

changed to:

        if k not in DEFAULT_CONFIG:

PS: -e AUTHOR=Me will issue a warning and will be ignored, since it's not in DEFAULT_CONFIG. Unfortunately, that's the limitation of implementation.

@justinmayer
Copy link
Member

Thanks for reporting this, @jwodder. The fix proposed by @avaris seems to resolve the problem in my (admittedly limited) testing, so I just pushed a commit including those changes: 45c5cb9 Thank you, @avaris! 👏

Another thing I noticed is that capitalized Boolean values, such as the one I provided as an example in the docs, yield this error:

CRITICAL: Expecting value: line 1 column 1 (char 0)

Lower-case Boolean values seem to work fine. For the moment, I changed the example in the docs to use a lower-case Boolean value. But it would be nice to fix this properly and help users avoid running into critical errors.

@justinmayer
Copy link
Member

Changing from:

types_to_cast = {int, str}

… to:

types_to_cast = {int, str, bool}

… seems to fix the aforementioned error and works with both lowercase and uppercase Boolean values. Anyone see any potentially unforeseen problems with this fix?

@justinmayer
Copy link
Member

justinmayer commented Aug 15, 2020

I went ahead and made the above-mentioned Boolean-related change. Despite tests passing locally, GitHub CI is reporting some kind of internal error that I don't understand and that I suspect is unrelated to the small change in the last commit. Maybe related to parallel testing via pytest-xdist, or maybe GitHub CI is just having a bad day. Who knows.

@jwodder: Can you test latest master and see whether the first item you reported here has been resolved?

@jwodder
Copy link
Contributor Author

jwodder commented Aug 15, 2020

@justinmayer The problem has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants