Skip to content

Commit

Permalink
Fix cleaner inheritance, parent model should be aliased during instan…
Browse files Browse the repository at this point in the history
…tiation (#452)
  • Loading branch information
disrupted authored Feb 8, 2024
1 parent d306e3d commit b90b05d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kpops/components/base_components/kafka_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def _resetter(self) -> KafkaConnectorResetter:
handlers=self.handlers,
**kwargs,
**self.model_dump(
exclude={"_resetter", "resetter_values", "resetter_namespace", "app"}
by_alias=True,
exclude={"_resetter", "resetter_values", "resetter_namespace", "app"},
),
app=KafkaConnectorResetterValues(
connector_type=self._connector_type.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _cleaner(self) -> ProducerAppCleaner:
return ProducerAppCleaner(
config=self.config,
handlers=self.handlers,
**self.model_dump(exclude={"_cleaner"}),
**self.model_dump(by_alias=True, exclude={"_cleaner"}),
)

@override
Expand Down
2 changes: 1 addition & 1 deletion kpops/components/streams_bootstrap/streams/streams_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _cleaner(self) -> StreamsAppCleaner:
return StreamsAppCleaner(
config=self.config,
handlers=self.handlers,
**self.model_dump(exclude={"_cleaner"}),
**self.model_dump(by_alias=True, exclude={"_cleaner"}),
)

@property
Expand Down
16 changes: 16 additions & 0 deletions tests/components/test_kafka_sink_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ def test_resetter_release_name(self, connector: KafkaSinkConnector):
assert isinstance(resetter, KafkaConnectorResetter)
assert connector._resetter.helm_release_name == CONNECTOR_CLEAN_RELEASE_NAME

def test_resetter_inheritance(self, connector: KafkaSinkConnector):
setattr(connector.resetter_values, "testKey", "foo")
resetter = connector._resetter
assert resetter
assert not hasattr(resetter, "_resetter")

assert not hasattr(resetter, "resetter_namespace")
assert resetter.namespace == connector.resetter_namespace

assert not hasattr(resetter, "resetter_values")
# check that resetter values are contained in resetter app values
assert (
connector.resetter_values.model_dump().items()
<= resetter.app.model_dump().items()
)

def test_connector_config_parsing(
self,
config: KpopsConfig,
Expand Down
6 changes: 6 additions & 0 deletions tests/components/test_producer_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def producer_app(
},
)

def test_cleaner_inheritance(self, producer_app: ProducerApp):
cleaner = producer_app._cleaner
assert cleaner
assert not hasattr(cleaner, "_cleaner")
assert cleaner.app == producer_app.app

def test_output_topics(self, config: KpopsConfig, handlers: ComponentHandlers):
producer_app = ProducerApp(
name=PRODUCER_APP_NAME,
Expand Down
13 changes: 13 additions & 0 deletions tests/components/test_streams_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
TopicConfig,
ToSection,
)
from kpops.components.streams_bootstrap.streams.model import StreamsAppAutoScaling
from kpops.components.streams_bootstrap.streams.streams_app import StreamsAppCleaner
from kpops.config import KpopsConfig, TopicNameConfig

Expand Down Expand Up @@ -78,6 +79,18 @@ def streams_app(
},
)

def test_cleaner_inheritance(self, streams_app: StreamsApp):
streams_app.app.autoscaling = StreamsAppAutoScaling(
enabled=True,
consumer_group="foo",
lag_threshold=100,
idle_replicas=1,
)
cleaner = streams_app._cleaner
assert cleaner
assert not hasattr(cleaner, "_cleaner")
assert cleaner.app == streams_app.app

def test_set_topics(self, config: KpopsConfig, handlers: ComponentHandlers):
streams_app = StreamsApp(
name=STREAMS_APP_NAME,
Expand Down

0 comments on commit b90b05d

Please sign in to comment.