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

fix: bug where plugin config would not update when default was empty dict #972

Merged
merged 1 commit into from
Aug 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/ape/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ def from_overrides(cls, overrides: Dict) -> "PluginConfig":

def update(root: Dict, value_map: Dict):
for key, val in value_map.items():
if key in root:
if isinstance(val, dict):
root[key] = update(root[key], val)
else:
root[key] = val
if key in root and isinstance(val, dict):
root[key] = update(root[key], val)
else:
root[key] = val

return root

Expand Down
14 changes: 14 additions & 0 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest

from ape.api import PluginConfig
from ape.exceptions import NetworkError
from ape.managers.config import DeploymentConfigCollection
from ape_ethereum.ecosystem import NetworkConfig
Expand Down Expand Up @@ -83,3 +84,16 @@ def test_config_access():
== getattr(config, "default-provider")
== "geth"
)


def test_plugin_config_updates_when_default_is_empty_dict():
class SubConfig(PluginConfig):
foo: int = 0
bar: int = 1

class MyConfig(PluginConfig):
sub: Dict[str, Dict[str, SubConfig]] = {}

overrides = {"sub": {"baz": {"test": {"foo": 5}}}}
actual = MyConfig.from_overrides(overrides)
assert actual.sub == {"baz": {"test": SubConfig(foo=5, bar=1)}}