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

Failure to initialize Config object #16

Closed
norlandrhagen opened this issue Jan 24, 2022 · 8 comments · Fixed by #20
Closed

Failure to initialize Config object #16

norlandrhagen opened this issue Jan 24, 2022 · 8 comments · Fixed by #20
Labels
bug Something isn't working

Comments

@norlandrhagen
Copy link

Issue description

Hi there, I'm trying to use Donfig for a project and ran into a potential bug when trying to setup a Config.

When setting up a Config and adding default values via a dict:

from donfig import Config

config = Config('cmip6_downscaling', defaults={'test_key':'key'})

I get the AttributeError:

AttributeError                            Traceback (most recent call last)
<ipython-input-1-6c2352fed93f> in <module>
      1 from donfig import Config
      2
----> 3 config = Config('project', defaults={'test_key':'key'})
      4
~/opt/anaconda3/envs/install/envs/cmip6/lib/python3.9/site-packages/donfig/config_obj.py in __init__(self, name, defaults, paths, env, env_var, root_env_var, env_prefix)
    366         self.config = {}
    367         self.config_lock = threading.Lock()
--> 368         self.refresh()
    369
    370     def __contains__(self, item):
~/opt/anaconda3/envs/install/envs/cmip6/lib/python3.9/site-packages/donfig/config_obj.py in refresh(self, **kwargs)
    440
    441         for d in self.defaults:
--> 442             update(self.config, d, priority='old')
    443
    444         update(self.config, self.collect(**kwargs))
~/opt/anaconda3/envs/install/envs/cmip6/lib/python3.9/site-packages/donfig/config_obj.py in update(old, new, priority)
    109
    110     """
--> 111     for k, v in new.items():
    112         k = canonical_name(k, old)
    113
AttributeError: 'str' object has no attribute 'items'

If I pass defaults as a list, the config object seems to be created without issues.

config = Config('project', defaults=[{'test_key':'key'}])
config.defaults
[{'test_key': 'key'}]
@djhoese djhoese added the bug Something isn't working label Jan 25, 2022
@djhoese
Copy link
Member

djhoese commented Jan 25, 2022

Thanks for filing this! This is definitely a bug in the documentation. As you've discovered defaults should be passed as a list of dictionaries.

Do you have any interest/time in correcting the documentation and submitting a pull request?

@norlandrhagen
Copy link
Author

Yeah totally! I'm a bit busy now, but I'll open up a PR soon to the docs.

Loving the package so far!

@djhoese
Copy link
Member

djhoese commented Feb 4, 2022

I'm preparing a new release so I thought I'd fix this docs issue myself. Sorry.

@jhamman
Copy link
Collaborator

jhamman commented Oct 13, 2022

fyi, I noticed this bug is still in the documentation: https://donfig.readthedocs.io/en/latest/configuration.html#configuration-object

config = Config('mypkg', defaults={'key1': 'default_val'}, paths=['/usr/local/etc/'])

Did the docs get rebuilt as part of the 0.7.0 release?

@djhoese
Copy link
Member

djhoese commented Oct 13, 2022

Looks like there is a syntax error in the sphinx config. Fixing...

@djhoese
Copy link
Member

djhoese commented Oct 13, 2022

🤦‍♂️ Looks like readthedocs was defaulting to Python 2.7 and the "master" branch so it was double-failing (py3 only and "main").

@djhoese
Copy link
Member

djhoese commented Oct 13, 2022

@jhamman If you do a forced refresh of the latest page it should show the brackets around the defaults argument.

Edit: And pull request builds on RTD should be enabled from now on.

@jhamman
Copy link
Collaborator

jhamman commented Oct 13, 2022

Thanks @djhoese - looks like its all working now.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants