Skip to content

Commit

Permalink
Fix issue with empty profile.yml file (#414)
Browse files Browse the repository at this point in the history
When using yaml.safe_load() on an empty text file, the returned
value is None rather than an empty dictionary as I expected. This
caused an error when adding the first value, as I would get the
error message "NoneType object does not support item assignment".

This patch changes a None value into an empty dictionary.
  • Loading branch information
aaronchantrill authored Jun 30, 2024
1 parent 34b14c1 commit 9a42888
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions naomi/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ def get_profile(command=""):
try:
with open(new_configfile, "r") as f:
_profile = yaml.safe_load(f)
# If the profile.yml file is empty, the _profile will be
# None rather than an empty dictionary. This will cause
# issues later.
if _profile is None:
_profile = {}
_profile_read = True
config_read = True
except (IOError, FileNotFoundError):
Expand Down

0 comments on commit 9a42888

Please sign in to comment.