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

Serialization: Host serialization cleanup #328

Conversation

Glutexo
Copy link
Collaborator

@Glutexo Glutexo commented Jul 3, 2019

Did a little cleanup of the (de)serialization methods. This consists of two changes, which I didn’t want to break up as they would be uncomfortably little:

  • Made the code more DRY and concise. Replaced some rather cryptic lines, leverage dict comprehension etc.
  • Made the deserialized objects trusted ones. Concentrated the validation/defaults logic into deserialization.

Both should make the code more durable and understandable. Although there is a change in the internal logic of the serialization, there are no changes for the code using the methods. No changes in the test nor in the overall behavior.

There are no unit tests in this pull request as the original methods were already untested. There is a separate PR (#325) with the unit tests. Some of them would have to be slightly changed to be green after merging this. Refer my rebased branch host_serialization_cleanup_with_tests to see the changes.

@Glutexo Glutexo self-assigned this Jul 3, 2019
@Glutexo Glutexo mentioned this pull request Jul 3, 2019
7 tasks
@Glutexo Glutexo changed the title Host serialization cleanup (wip) Host serialization cleanup Jul 3, 2019
@Glutexo
Copy link
Collaborator Author

Glutexo commented Jul 3, 2019

Found some issues. Working on fixing them.

@Glutexo Glutexo force-pushed the host_serialization_cleanup branch from be58344 to 4c08923 Compare July 4, 2019 12:45
@Glutexo
Copy link
Collaborator Author

Glutexo commented Jul 4, 2019

Forgot about fixing canonical facts, so it is deserialized as trusted. Fixed.

@Glutexo Glutexo changed the title (wip) Host serialization cleanup Host serialization cleanup Jul 4, 2019
@Glutexo Glutexo force-pushed the host_serialization_cleanup branch from 4c08923 to 6cff9a8 Compare July 17, 2019 07:46
@Glutexo
Copy link
Collaborator Author

Glutexo commented Jul 17, 2019

Rebased on the current state of split_inventory_service. The pull request is now mergeable again and the tests are 🍏.

I was thinking a bit about the internal Python representation of the canonical facts. It would make sense for them to be a namedtuple. I wanted to start with having a dict strictly with None values. That doesn’t work though, because the internal object is currently used as a database model and we need the canonical facts to be stored without the empty values. Otherwise the JSONB comparison to search by canonical facts wouldn’t work.

I’d like to see this transition when splitting the database model from the internal objects (#309) split, but that’s not a task for today.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Jul 24, 2019

May I ask for a review of this, please? Thanks!

@Glutexo Glutexo force-pushed the host_serialization_cleanup branch from 6cff9a8 to 06507fb Compare July 25, 2019 09:25
@Glutexo
Copy link
Collaborator Author

Glutexo commented Jul 25, 2019

Rebased.

@Glutexo Glutexo force-pushed the host_serialization_cleanup branch from 06507fb to 1e01204 Compare July 29, 2019 12:01
@Glutexo
Copy link
Collaborator Author

Glutexo commented Jul 29, 2019

Rebased to resolve conflicts, but the rebase went without one. Strange.

@Glutexo Glutexo force-pushed the host_serialization_cleanup branch from 1e01204 to 8335d34 Compare July 31, 2019 17:20
@Glutexo
Copy link
Collaborator Author

Glutexo commented Jul 31, 2019

Rebased to fix formatting conflicts.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Aug 1, 2019

Rebased to resolve conflicts. Also amended the commits so they don't introduce new rule violations. Removed forgotten debugging-related code.

Reviewed the style of the (de)serialization methods. Removed redundant
or rather cryptic instructions. Leveraged comprehensions, dried a few
bits of code. Made the code more concise and expressive. Unified names
a bit.
Change the (de)serialization logic, so the serialization expects that
the object is valid. All default values and validation happens now upon
deserialization. That concentrates the logic into a single place.
@Glutexo
Copy link
Collaborator Author

Glutexo commented Aug 6, 2019

Rebased to resolve conflicts. Mergeable again. I’ll split it into two pull requests, to it’s easier to review. If anybody gets to review before that, feel free to merge.

@Glutexo Glutexo changed the title Host serialization cleanup Serialization: Host serialization cleanup Oct 11, 2019
@jharting jharting added the conflict needs to be resolved and rebased label Nov 1, 2019
@Glutexo Glutexo closed this Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflict needs to be resolved and rebased
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants