Skip to content

Commit

Permalink
Fixes #75
Browse files Browse the repository at this point in the history
In memory dictionaries would be auto-updated and thus the
item watch functions would never get called. Performing
a deep copy of the current config on init and when the
config changes ensures that we are comparing new
dictionaries when someone changes the in-memory dict.
  • Loading branch information
loganasherjones committed Jun 8, 2018
1 parent 632dace commit a05513c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Expand Up @@ -5,6 +5,7 @@ History
0.3.1 (2018-06-07)
---------
* Fixed an issue with environment loading (#74)
* Fixed an issue with watching in-memory dictionaries (#75)

0.3.0 (2018-06-02)
---------
Expand Down
6 changes: 4 additions & 2 deletions tests/spec_test.py
Expand Up @@ -870,13 +870,15 @@ def change_config(label):
real_world_spec.add_source('label3', 'dict', data=safe_data)

real_world_spec.spawn_watcher(label, target=overall_handler)
time.sleep(0.1)

change_config(label)

wait_time = 0.0

while any(flags.values()) and wait_time <= 90:
while any(flags.values()) and wait_time <= 3:
time.sleep(0.25)
wait_time += 0.25

assert not all(flags.values())
for flag in flags.values():
assert not flag
8 changes: 6 additions & 2 deletions yapconf/handlers.py
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import copy

from watchdog.events import RegexMatchingEventHandler

import yapconf
Expand All @@ -12,7 +14,9 @@ class ConfigChangeHandler(object):
"""

def __init__(self, current_config, spec, user_handler=None):
self.current_config = current_config
# We perform a deep copy so that we can accurately assess whether
# or not the value has changed for in-memory dictionaries.
self.current_config = copy.deepcopy(current_config)
self.spec = spec
self.user_handler = user_handler

Expand All @@ -26,7 +30,7 @@ def handle_config_change(self, new_config):
if self.user_handler:
self.user_handler(self.current_config, new_config)
self._call_spec_handlers(new_config)
self.current_config = new_config
self.current_config = copy.deepcopy(new_config)

def _call_spec_handlers(self, new_config):
flattened_config = yapconf.flatten(new_config, self.spec._separator)
Expand Down

0 comments on commit a05513c

Please sign in to comment.