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

DM-35386 Fix Serialization of ConfigurableActionStructField #695

Merged
merged 1 commit into from
Jul 6, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ def items(self) -> Iterable[Tuple[str, ActionTypeVar]]:
for name in self.fieldNames:
yield name, getattr(self, name)

def __bool__(self) -> bool:
return bool(self._attrs)


T = TypeVar("T", bound="ConfigurableActionStructField")

Expand Down Expand Up @@ -274,8 +277,8 @@ def __set__(self, instance: Config,
else:
# An actual value is being assigned check for what it is
if isinstance(value, self.StructClass):
# If this is a ConfigurableActionStruct, we need to make our own
# copy that references this current field
# If this is a ConfigurableActionStruct, we need to make our
# own copy that references this current field
value = self.StructClass(instance, self, value._attrs, at=at, label=label)
elif isinstance(value, (SimpleNamespace, Struct)):
# If this is a a python analogous container, we need to make
Expand Down Expand Up @@ -355,8 +358,11 @@ def toDict(self, instance):
def save(self, outfile, instance):
actionStruct = self.__get__(instance)
fullname = _joinNamePath(instance._name, self.name)

# Ensure that a struct is always empty before assigning to it.
outfile.write(f"{fullname}=None\n")

if actionStruct is None:
outfile.write(u"{}={!r}\n".format(fullname, actionStruct))
return

for v in actionStruct:
Expand Down