Skip to content

Commit

Permalink
fix: regression in include with namespace no overwrite (#39)
Browse files Browse the repository at this point in the history
We fix a regression with the include method when using a namespace
for sub-configuration with like-named items.
  • Loading branch information
P403n1x87 authored Oct 22, 2024
1 parent 397c93f commit b982cea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions envier/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,6 @@ def include(
or isinstance(v, type)
and issubclass(v, Env)
}
if not overwrite:
overlap = set(cls.__dict__.keys()) & set(to_include.keys())
if overlap:
raise ValueError("Configuration clashes detected: {}".format(overlap))

own_prefix = _normalized(getattr(cls, "__prefix__", ""))

Expand All @@ -434,6 +430,11 @@ def include(

return None

if not overwrite:
overlap = set(cls.__dict__.keys()) & set(to_include.keys())
if overlap:
raise ValueError("Configuration clashes detected: {}".format(overlap))

other_prefix = getattr(env_spec, "__prefix__", "")
for k, v in to_include.items():
if getattr(cls, k, None) is not v:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,14 @@ class GlobalConfig(Env):
__prefix__ = "myapp"

debug_mode = Env.var(bool, "debug", default=False)
enable = Env.var(bool, "enable", default=True)

class ServiceConfig(Env):
__prefix__ = "service"

host = Env.var(str, "host", default="localhost")
port = Env.var(int, "port", default=3000)
enable = Env.var(bool, "enable", default=False)

GlobalConfig.include(ServiceConfig, namespace="service")
with pytest.raises(ValueError):
Expand Down

0 comments on commit b982cea

Please sign in to comment.