Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scampbell5 opened this issue Jun 13, 2024 · 6 comments · Fixed by #4515
Closed

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

scampbell5 opened this issue Jun 13, 2024 · 6 comments · Fixed by #4515
Assignees
Labels
bug Something isn't working event_sources Event Source Data Class utility

Comments

@scampbell5
Copy link

scampbell5 commented Jun 13, 2024

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

@scampbell5 scampbell5 added bug Something isn't working triage Pending triage from maintainers labels Jun 13, 2024
Copy link

boring-cyborg bot commented Jun 13, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@leandrodamascena
Copy link
Contributor

Hi @scampbell5! Thanks for pointing out this bug. Actually, you're 100% right, these fields should be int instead of str. Do you want to submit a PR to fix this? We can work together to merge it.

References:
https://docs.aws.amazon.com/lambda/latest/dg/with-kafka.html
https://github.com/aws/aws-lambda-go/blob/main/events/kafka.go

@leandrodamascena leandrodamascena moved this from Triage to Pending customer in Powertools for AWS Lambda (Python) Jun 13, 2024
@leandrodamascena leandrodamascena added event_sources Event Source Data Class utility and removed triage Pending triage from maintainers labels Jun 13, 2024
@leandrodamascena leandrodamascena self-assigned this Jun 13, 2024
@scampbell5
Copy link
Author

@leandrodamascena Appreciate the quick response! I'll work on putting together a PR later tonight to fix this.

@leandrodamascena
Copy link
Contributor

Perfect, let me know if you have any questions or blocks, and we can work together on this!

We truly appreciate when the community contributes to the project. 🚀

@scampbell5
Copy link
Author

@leandrodamascena I've submitted this PR if you don't mind taking a look when you have time: #4515

Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event_sources Event Source Data Class utility
Projects
Status: Shipped
2 participants