✨ Fix deserialization issues#139
Conversation
4ff5bef to
d3df1db
Compare
|
|
||
|
|
||
| @dataclass | ||
| class PublishedPlaintextTally(ElectionObjectBase): |
There was a problem hiding this comment.
These classes were made due to the unique serialization to just remove the other elements of the Tally. This simplifies it to just the items to be published. Drastically simplifying the deserialization as well.
e71551c to
798df06
Compare
|
|
||
| if self.REMOVE_OUTPUT: | ||
| rmtree(RESULTS_DIR) | ||
| def verify_results(self) -> None: |
There was a problem hiding this comment.
This test deserializes all the outputs just made into the file directory.
| READ: str = "r" | ||
| JSON_PARSE_ERROR = '{"error": "Object could not be parsed due to json issue"}' | ||
| # TODO Issue #??: Jsons library incorrectly dumps class method | ||
| FROM_JSON_FILE = '"from_json_file": {}, ' |
There was a problem hiding this comment.
This is handling a bug with jsons that an issue still needs to be made for. I'll update PR accordingly.
Essentially every output file has this classmethod appended.
| :param strip_privates: strip private variables | ||
| :return: the json representation of this object | ||
| """ | ||
| set_serializers() |
There was a problem hiding this comment.
These were moved into here to reduce turning these on every time they needed to be used.
| :param description_hash: the hash of the election metadata | ||
| """ | ||
|
|
||
| # What's a crypto_base_hash? |
There was a problem hiding this comment.
This needs to get fixed.
| you're absolutely, positively, certain the input is in-bounds. | ||
| """ | ||
| return ElementModP(mpz(i)) | ||
| m = mpz(int(i)) |
There was a problem hiding this comment.
Want to create some consistency with these so that all the methods look the same.
| write_json_file(self.to_json(strip_privates), file_name, file_path) | ||
|
|
||
| @classmethod | ||
| def from_json_file(cls, file_name: str, file_path: str = "") -> T: |
There was a problem hiding this comment.
This could use just the file_path to reduce the length of this method. This concatenation could be moved out. I only kept it because the write had that but it could be said that neither need it.
|
|
||
| set_deserializer( | ||
| lambda usage_string, cls, **_: ProofUsage[usage_string], ProofUsage | ||
| lambda none, cls, **_: None |
There was a problem hiding this comment.
This deserialization from "None" is critical. Perhaps we could change it to serialize to null as well and have a deserialization from null to None but regardless this needs to exist for Ballots to be deserialized.
|
|
||
| return ElectionDescription( | ||
| election_scope_id=draw(languages()), | ||
| election_scope_id=draw(emails()), |
798df06 to
7f9b27b
Compare
- Create functional style make method for ElectionContext - Integrate it into Tests
- Create make method for CiphertextAcceptedBallot and CiphertextBallot - Update use cases - Remove todo
- Cast str to int ahead of cast
- Add equality statements - Remove frozen - Use unsafe_hash to remove unnecessary hash function
- Ballot store will now always return Ballots for all() method. This is the main use case and reduces the need to check for null around the store. Fixed attached integration test.
- ✨Remove InitVar for Plaintext Tally - Remove InitVar for Selection - Remove PostVar - Plaintext Tally Changes - Sample Generator Fixes
"None" created issues due Optional that also have custom deserialization. The solution for this is ensuring all NoneTypes are checked against a string before running default deserialization. - Suppress Warning in serializable
7f9b27b to
539338e
Compare
Issue
Fixes #132
Fixes #120
Fixes #122 while obsoleting PR #123
Description
For many of the core ElectionGuard classes, deserialization of a serialized class does not yield the original or has issues.
Replace post_init with factory methods
Deserialization has issues with the post_init methods that we'd been using, similar to
InitVar. Factorymake_methods were created for constructing the classes.Resolve equality methods for testing
To make sure equality testing worked among the core ElectionGuard classes, there were some additional changes. Some of them use @DataClass(eq=True...) to auto-generate the methods. This doesn't work for lists which might come back in a different order than they were written out. For those cases, existing _list_eq() method is used in custom eq methods.
Remove frozen tag
A frozen=True dataclass with a non-frozen superclass causes an inheritance error (ignored by Python, flagged by PyCharm) to have . Since our Serializable isn't frozen, this is a problem. The frozen attribute was removed from the dataclasses only relevant to this PR.
Change crypto_hash to class method from property
Add serialization methods for datetime
Allow strings to be passed into mpz for conversion
Resolve issues with Proof deserialization
Proof serialized correctly but had issues deserializing with the conversions
Add "None" deserialization
"None" was not deserializing properly and caused issues with certain Optionals
Testing
test_serializabletest_end_to_end_electionChecklist
🚨Please review the guidelines for contributing to this repository.
💚Thank you!