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

modify statedict: enable storing dict via json.dump #1410

Merged
merged 1 commit into from Nov 28, 2020

Conversation

@lukebfox
Copy link
Member

@lukebfox lukebfox commented Oct 4, 2020

attr_property has the ability to set state for attributes created with the "json" type with values of the list or dict type.

nixops/nixops/util.py

Lines 487 to 488 in a287225

elif type == "json":
self._set_attr(name, json.dumps(x, cls=NixopsEncoder))

The diff engine uses the newer StateDict, which has it's own setter for state.

nixops/nixops/state.py

Lines 31 to 37 in 78a8815

v = value
if isinstance(value, list):
v = json.dumps(value, cls=nixops.util.NixopsEncoder)
c.execute(
"insert or replace into ResourceAttrs(machine, name, value) values (?, ?, ?)",
(self.id, key, v),
)

The nixops-aws VPC resources which motivated the diff engine never had a dict case, so I guess it was left out, but it's important to keep this functionality for other resources which want to use the diff engine in the future (I am working on some).

…erty
@adisbladis adisbladis merged commit faed063 into NixOS:master Nov 28, 2020
10 checks passed
10 checks passed
parsing
Details
build
Details
black
Details
mypy
Details
flake8
Details
mypy-ratchet
Details
coverage
Details
docs
Details
poetry-up-to-date
Details
docs/readthedocs.org:nixops Read the Docs build succeeded!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.