Apiv2 fix unions#1125
Merged
Merged
Conversation
The original implementation supported renaming of fields in the dataclasses. This was however used only in one dataclass, and this dataclass was never serialized or deserialized using the functions from the pcs.common.interface.dto module - this was effectively complicated dead code.
Python 3.11 introduced StrEnum and changed how enums inheriting from str and Enum behave when they are printed: "EnumName.VALUE" instead of original "VALUE". We changed the Enums in our code that inherit from StrEnum instead of str, Enum, to preserve the pre 3.11 behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #1096
We analyzed the code that caused the issues, and realized multiple things.
The original purpose of the code in
pcs/common/interface/dto.pywas to rename dataclass attributes according to their META_NAME meta attribute. Later, enum translation was added in commit 9e6134d, which tried to fix issues with serialization of enum values. However, we analyzed the code and realized:anyin DTO for APIv2 result (pcs/common/async_tasks/dto.py), which means that any transformations are skippedThis means that the code was a complicated piece of dead code and we decided that the best course of action is to remove it, and simplify the serialization and deserialization functions. This fixes the issue described in #1096
We also realized, that we do not need to transform Enums into their values during serialization, as json can transform Enums that are also inheriting from a primitive type. There were however changes in Python 3.11 (https://blog.pecar.me/python-enum/) that caused the original issue that the 9e6134d tried to solve. The simpler solution is to replace all instances of inheriting from
str, enum.Enumto inherit fromenum.StrEnum.