Skip to content

Commit

Permalink
admin: prevent unset'ing required settings
Browse files Browse the repository at this point in the history
Any setting with `default = NO_DEFAULT` cannot be unset; e.g., `core.owner`
  • Loading branch information
HumorBaby committed Apr 15, 2019
1 parent cbf8fb3 commit f8779e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sopel/config/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def __get__(self, instance, owner=None):

def __set__(self, instance, value):
if value is None:
if self.default == NO_DEFAULT:
raise ValueError('Cannot unset an option with a required value.')
instance._parser.remove_option(instance._section_name, self.name)
return
value = self.serialize(value)
Expand Down
5 changes: 4 additions & 1 deletion sopel/modules/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,10 @@ def unset_config(bot, trigger):
bot.reply('Invalid command; no value should be provided to unset.')
return

setattr(section, option, None)
try:
setattr(section, option, None)
except ValueError:
bot.reply('Cannot unset {}.{}; it is a required option.'.format(section_name, option))


@sopel.module.require_privmsg
Expand Down

0 comments on commit f8779e1

Please sign in to comment.