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

Empty runtime config file produces exception #551

Closed
tyhoff opened this Issue Jul 6, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@tyhoff

tyhoff commented Jul 6, 2018

Issue

When running Invoke with an empty runtime config file, the following exception is hit.

$ inv --list
Traceback (most recent call last):
  File "/Users/username/miniconda2/envs/env/bin/inv", line 11, in <module>
    sys.exit(program.run())
  File "/Users/username/miniconda2/envs/env/lib/python2.7/site-packages/invoke/program.py", line 313, in run
    self.create_config()
  File "/Users/username/miniconda2/envs/env/lib/python2.7/site-packages/invoke/program.py", line 243, in create_config
    self.config = self.config_class()
  File "/Users/username/miniconda2/envs/env/lib/python2.7/site-packages/invoke/config.py", line 641, in __init__
    self.merge()
  File "/Users/username/miniconda2/envs/env/lib/python2.7/site-packages/invoke/config.py", line 927, in merge
    self._merge_file('user', "Per-user")
  File "/Users/username/miniconda2/envs/env/lib/python2.7/site-packages/invoke/config.py", line 951, in _merge_file
    merge_dicts(self._config, data)
  File "/Users/username/miniconda2/envs/env/lib/python2.7/site-packages/invoke/config.py", line 1170, in merge_dicts
    for key, value in updates.items():
AttributeError: 'NoneType' object has no attribute 'items'

Desired Result

Passing in a valid, empty .yml file should not throw an exception.

Steps to reproduce

  1. Create a new directory
  2. Create a simple tasks.py file
from invoke import task, Collection, Config

@task
def hello(ctx):
    print("Hello {}".format(ctx.name))
  1. Create an empty ~/.invoke.yaml file
  2. Run invoke --list

Fix

I think it's reasonable to just return early if the dict being passed in is None.

diff --git a/invoke/config.py b/invoke/config.py
index 6d13ac08..84501133 100644
--- a/invoke/config.py
+++ b/invoke/config.py
@@ -1174,6 +1174,9 @@ def merge_dicts(base, updates):

     .. versionadded:: 1.0
     """
+    if not updates:
+        return base
+
     # TODO: for chrissakes just make it return instead of mutating?
     for key, value in updates.items():
         # Dict values whose keys also exist in 'base' -> recurse

Let me know if you need any more information or want me to throw up a commit!

@bitprophet

This comment has been minimized.

Member

bitprophet commented Jul 10, 2018

Feel like I ran into this myself recently too 🙃 thanks for the detailed report! I agree that it ought to just no-op instead of exploding.

@bitprophet

This comment has been minimized.

Member

bitprophet commented Jul 10, 2018

Actually, this is (perhaps unsurprisingly) an old problem and so there's an existing issue already - #270! Rolling into that. I'm just gonna fix it now either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment