Skip to content

Fix OverflowError in offsets_for_times() when timestamp is non-finite float#3119

Open
koteshyelamati wants to merge 1 commit into
dpkp:masterfrom
koteshyelamati:koteshyelamati-patch-1
Open

Fix OverflowError in offsets_for_times() when timestamp is non-finite float#3119
koteshyelamati wants to merge 1 commit into
dpkp:masterfrom
koteshyelamati:koteshyelamati-patch-1

Conversation

@koteshyelamati

Copy link
Copy Markdown

Bug

offsets_for_times() converts each timestamp value with int(ts). If ts is float('inf') or float('nan'), this raises an OverflowError (or ValueError for nan) instead of the expected ValueError with a clear message.

Reproducer:

consumer = KafkaConsumer(bootstrap_servers='localhost:9092')
tp = TopicPartition('my-topic', 0)
consumer.offsets_for_times({tp: float('inf')})
# OverflowError: cannot convert float infinity to integer

Fix

Wrap int(ts) in a try/except that catches ValueError, TypeError, and OverflowError, and re-raises as ValueError with a descriptive message — consistent with the existing negative-timestamp check.

…nity

Add error handling for invalid timestamps in Kafka consumer.
@dpkp

dpkp commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Why did or do you expect a ValueError in this case? The docstring only claims to raise ValueError for negative timestamps. I'm not sure how changing OverflowError to ValueError improves this api contract?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants