Fix bugs arising from None and empty dicts causing dupes.
This commit is contained in:
parent
9da8b4234e
commit
1325183514
@ -92,13 +92,32 @@ class Resource:
|
|||||||
though should only be used where necessary and sensible to do so.
|
though should only be used where necessary and sensible to do so.
|
||||||
"""
|
"""
|
||||||
# extra_params: Optional[frozendict[str, str]] = None
|
# extra_params: Optional[frozendict[str, str]] = None
|
||||||
extra_params: Optional[frozendict] = None
|
extra_params: Optional[frozendict] = attr.ib(default=None)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
extra_str = "" if not self.extra_params else f" {self.extra_params!r}"
|
extra_str = "" if not self.extra_params else f"{self.extra_params!r}"
|
||||||
sous_str = "" if not self.sous else f" on {self.sous}"
|
sous_str = "" if not self.sous else f" on {self.sous}"
|
||||||
return f"{self.kind}({self.id}){extra_str}{sous_str}"
|
return f"{self.kind}({self.id}){extra_str}{sous_str}"
|
||||||
|
|
||||||
|
@extra_params.validator
|
||||||
|
def _check_extra_params(self, _attribute, value):
|
||||||
|
if value is not None and len(value) == 0:
|
||||||
|
raise ValueError(
|
||||||
|
"Resources must not contain an empty extra_params dict."
|
||||||
|
" Use None instead."
|
||||||
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def new_lenient(
|
||||||
|
kind: str, id: str, sous: Optional[str], extra_params: Optional[frozendict]
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Alternative constructor which will correct an empty extra_params dict.
|
||||||
|
"""
|
||||||
|
if extra_params is not None and len(extra_params) == 0:
|
||||||
|
extra_params = None
|
||||||
|
return Resource(kind, id, sous, extra_params)
|
||||||
|
|
||||||
|
|
||||||
@attr.s(auto_attribs=True)
|
@attr.s(auto_attribs=True)
|
||||||
class ResourceMeta:
|
class ResourceMeta:
|
||||||
|
@ -70,7 +70,7 @@ class Preparation:
|
|||||||
if sous == "(self)":
|
if sous == "(self)":
|
||||||
sous = self._current_recipe.recipe_context.sous
|
sous = self._current_recipe.recipe_context.sous
|
||||||
|
|
||||||
resource = Resource(
|
resource = Resource.new_lenient(
|
||||||
requirement, identifier, sous, frozendict(extra_identifiers)
|
requirement, identifier, sous, frozendict(extra_identifiers)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ class Preparation:
|
|||||||
if sous == "(self)":
|
if sous == "(self)":
|
||||||
sous = self._current_recipe.recipe_context.sous
|
sous = self._current_recipe.recipe_context.sous
|
||||||
|
|
||||||
resource = Resource(
|
resource = Resource.new_lenient(
|
||||||
requirement, identifier, sous, frozendict(extra_identifiers)
|
requirement, identifier, sous, frozendict(extra_identifiers)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user