Skip to content

Bug: KafkaEventRecord Incorrect types for offset and partition properties #4504

Closed
@scampbell5

Description

@scampbell5

Expected Behaviour

The properties for offset and partition are the correct int type on the KafkaEventRecord class.

Current Behaviour

The properties for offset and partition on the KafkaEventRecord are currently defined as str type.

Code snippet

class KafkaEventRecord(DictWrapper):
    @property
    def topic(self) -> str:
        """The Kafka topic."""
        return self["topic"]

    @property
    def partition(self) -> str:
        """The Kafka record parition."""
        return self["partition"]

    @property
    def offset(self) -> str:
        """The Kafka record offset."""
        return self["offset"]

https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/kafka_event.py#L18

Possible Solution

Change the type to int for the partition and offset properties on the KafkaEventRecord class.

Steps to Reproduce

from aws_lambda_powertools.utilities.data_classes import event_source, KafkaEvent

@event_source(data_class=KafkaEvent)
def lambda_handler(event: KafkaEvent, context):
    assert isinstance(event.record.offset, int)
    assert isinstance(event.record.partition, int)

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.11

Packaging format used

Lambda Layers

Debugging logs

No response

Metadata

Metadata

Labels

bugSomething isn't workingevent_sourcesEvent Source Data Class utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions