Skip to content

Apiv2 fix unions#1125

Merged
tomjelinek merged 3 commits into
mainfrom
apiv2-fix-unions
May 15, 2026
Merged

Apiv2 fix unions#1125
tomjelinek merged 3 commits into
mainfrom
apiv2-fix-unions

Conversation

@Pederrr
Copy link
Copy Markdown
Member

@Pederrr Pederrr commented May 14, 2026

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.py was 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:

  • META_NAME renaming is used only in one DTO, and this renaming mechanism is not even used for serialization and deserialization of that DTO
  • This mechanism does not work correctly in APIv2: It translates the data based on type hints, but the return value of library commands is typed as any in DTO for APIv2 result (pcs/common/async_tasks/dto.py), which means that any transformations are skipped

This 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.Enum to inherit from enum.StrEnum.

Pederrr added 3 commits May 14, 2026 13:19
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.
@Pederrr Pederrr requested a review from tomjelinek as a code owner May 14, 2026 11:42
@Pederrr Pederrr temporarily deployed to testing-farm-apikey May 14, 2026 11:42 — with GitHub Actions Inactive
@Pederrr Pederrr temporarily deployed to testing-farm-apikey May 14, 2026 11:42 — with GitHub Actions Inactive
@github-actions
Copy link
Copy Markdown

Testing Farm results

namecomposearchstatusstarted (UTC)timelogs
CentOS-Stream-10CentOS-Stream-10x86_64✅ passed14.05.2026 11:42:288min 52stest pipeline

Copy link
Copy Markdown
Member

@tomjelinek tomjelinek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tomjelinek tomjelinek merged commit eef9a41 into main May 15, 2026
5 checks passed
@tomjelinek tomjelinek deleted the apiv2-fix-unions branch May 15, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple API v2/v1 commands not working after the recent Python 3.15 fixes

2 participants