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

registry: Avoid calling Value.setValue() when closing registry #1601

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ def close(registry, filename, private=True):
if value._showDefault:
lines.append('#\n')
try:
x = value.__class__(value._default, value._help)
# We set setDefault to False and manually call
# Value._setValue, just in case the class inherits
# Value.setValue to set some global state (#1349)
x = value.__class__(value._default, value._help,
setDefault=False)
x.value = value._default
except Exception as e:
exception('Exception instantiating default for %s:' %
value._name)
Expand Down
18 changes: 18 additions & 0 deletions test/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,24 @@ def testSpacesValues(self):
registry.open_registry(filename)
self.assertEqual(conf.supybot.networks.test.password(), ' foo ')

def testSetValueUncalledOnClose(self):
values_set = 0
class StringWithSetLogging(registry.String):
def setValue(self, v):
nonlocal values_set
values_set += 1

super(StringWithSetLogging, self).setValue(v)

group = registry.Group()
group.setName('group')
conf.registerGlobalValue(group, 'string', StringWithSetLogging('test', 'help'))
group.string.set('mrrp')

filename = conf.supybot.directories.conf.dirize('setvaluecalls.conf')
registry.close(group, filename)
self.assertEqual(values_set, 2)

def testReload(self):
import supybot.world as world
with conf.supybot.reply.whenAddressedBy.chars.context('@'):
Expand Down
Loading