Skip to content

Commit

Permalink
create a copy before return
Browse files Browse the repository at this point in the history
  • Loading branch information
jieru-hu committed Jan 22, 2021
1 parent ed75222 commit 353af48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions hydra/core/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ def instance(cls: Any, *args: Any, **kwargs: Any) -> Any:

@staticmethod
def get_state() -> Any:
instances = deepcopy(Singleton._instances)
try:
from hydra.core.plugins import Plugins

del Singleton._instances[Plugins]
del instances[Plugins]
except KeyError:
pass
return {
"instances": Singleton._instances,
"instances": instances,
"omegaconf_resolvers": deepcopy(BaseContainer._resolvers),
}

Expand Down
8 changes: 8 additions & 0 deletions tests/test_config_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ def test_get_config_header(cfg_text: str, expected: Any, sep: str) -> None:
ConfigSource._get_header_dict(cfg_text)


def test_singleton_get_state(hydra_restore_singletons: Any) -> None:
s = Singleton.get_state()
assert Plugins not in s["instances"]
assert Plugins in Singleton._instances
Singleton.set_state(s)
assert Plugins in Singleton._instances


def test_restore_singleton_state_hack() -> None:
"""
This is a hack that allow us to undo changes to the ConfigStore.
Expand Down

0 comments on commit 353af48

Please sign in to comment.