Skip to content

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

Closed

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

Activity

  1. added
    bugSomething isn't working
    triagePending triage from maintainers
    on Jun 13, 2024
  2. boring-cyborg commented on Jun 13, 2024

    @boring-cyborg

    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

  3. leandrodamascena commented on Jun 13, 2024

    @leandrodamascena
    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

  4. moved this from Triage to Pending customer in Powertools for AWS Lambda (Python)on Jun 13, 2024
  5. added
    event_sourcesEvent Source Data Class utility
    and removed
    triagePending triage from maintainers
    on Jun 13, 2024
  6. scampbell5 commented on Jun 13, 2024

    @scampbell5
    Author

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

  7. leandrodamascena commented on Jun 13, 2024

    @leandrodamascena
    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. 🚀

  8. scampbell5 commented on Jun 13, 2024

    @scampbell5
    Author

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

  9. moved this from Pending customer to Coming soon in Powertools for AWS Lambda (Python)on Jun 13, 2024
  10. github-actions commented on Jun 13, 2024

    @github-actions
    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingevent_sourcesEvent Source Data Class utility

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions