Skip to content

Commit

Permalink
fix: serialization WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sujuka99 committed Oct 10, 2023
1 parent 7c81a82 commit adde6ca
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions kpops/components/streams_bootstrap/streams/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

from pydantic import ConfigDict, Field, model_serializer
from pydantic import ConfigDict, Field, SerializationInfo, model_serializer
from pydantic.alias_generators import to_snake

from kpops.components.base_components.base_defaults_component import deduplicate
Expand Down Expand Up @@ -72,17 +72,58 @@ def add_extra_input_topics(self, role: str, topics: list[str]) -> None:
)

@model_serializer(mode="wrap", when_used="always")
def serialize_model(self, handler) -> dict[str, Any]:
def serialize_model(self, handler, info: SerializationInfo) -> dict[str, Any]:
# class _SerInfoClone:
# def __init__(
# self,
# include,
# exclude,
# mode,
# by_alias,
# exclude_unset,
# exclude_default,
# exclude_none,
# round_trip,
# ):
# self.include = include
# self.exclude = exclude
# self.mode = mode
# self.by_alias = by_alias
# self.exclude_unset = exclude_unset
# self.exclude_default = exclude_default
# self.exclude_none = exclude_none
# self.round_trip = round_trip

# info2: _SerInfoClone = _SerInfoClone(
# info.include,
# info.exclude,
# info.mode,
# info.by_alias,
# True,
# True,
# True,
# info.round_trip,
# )
# breakpoint()
# return handler(self, info2)
result = handler(self)
# if dict(result.items()).get("extraInputTopics"):
# breakpoint()
extra_fields = set()
if self.model_extra is not None:
extra_fields = set(self.model_extra.keys())
# fields = extra_fields.union(self.model_fields_set)
fields = extra_fields.union(self.model_fields_set)
return {
if self.extra_input_topics:
fields.add("extra_input_topics")
if self.extra_input_patterns:
fields.add("extra_input_patterns")
if self.extra_output_topics:
fields.add("extra_output_topics")
filtered_result_extra_set = {
k: v for k, v in result.items() if ((to_snake(k) in fields) or k in fields)
}
return filtered_result_extra_set

Check failure on line 126 in kpops/components/streams_bootstrap/streams/model.py

View workflow job for this annotation

GitHub Actions / Test (ubuntu-22.04, 3.10)

[*] Unnecessary assignment to `filtered_result_extra_set` before `return` statement


class StreamsAppAutoScaling(CamelCaseConfigModel, DescConfigModel):
Expand Down

0 comments on commit adde6ca

Please sign in to comment.