-
Notifications
You must be signed in to change notification settings - Fork 183
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
Commit structure validation failure: TP != TopicPartition #539
Comments
If I change this faust/faust/transport/drivers/aiokafka.py Line 715 in 4a23420
aiokafka_offsets = {
tp: OffsetAndMetadata(offset, "")
for tp, offset in offsets.items()
if tp in self.assignment()
}
self.tp_last_committed_at.update({tp: now for tp in aiokafka_offsets})
await consumer.commit(aiokafka_offsets) to this: aiokafka_offsets = {
TopicPartition(tp.topic, tp.partition): OffsetAndMetadata(offset, "")
for tp, offset in offsets.items()
if tp in self.assignment()
}
self.tp_last_committed_at.update({TP(tp.topic, tp.partition): now for tp in aiokafka_offsets})
await consumer.commit(aiokafka_offsets) it works. |
Interesting, let's get a PR opened with these changes and talk about this further there. I've never seen this issue before, so I'm curious to know what code you're running that triggered this. |
@richardhundt as far as I can see a consumer has the function faust/faust/transport/drivers/aiokafka.py Line 258 in 87a80a9
But it seems to be not used anywhere 🤔 |
@dabdada also, when it fetches the faust/faust/transport/consumer.py Line 137 in 4a23420
|
I do suspect this to be simply for internal type usage. Can you provide a minimal example of code that raises the error? As well as @wbarnha I didn't experience anything like this and now wonder why 😁 |
@dabdada Are you saying that faust/faust/transport/drivers/aiokafka.py Line 711 in 4a23420
Because, you can just inspect it, it's not hard to see that it calls Surely seeing that The real question is why has this ever worked? Does EDIT: also the stack trace proves my point ;) It actually logs the dictionary which causes the error: Current assignment: {TP(topic='test-uploads', partition=0), TP(topic='test-dgtal-cases-documents-list-changelog', partition=0), TP(topic='test-dgtal.worker.agents.health_agent', partition=0), TP(topic='test-transactions', partition=0), TP(topic='dgtal Those are |
I've added comments inline to show what's going on: # we're about to build a `Dict[TP, OffsetAndMetadata]`...
aiokafka_offsets = {
tp: OffsetAndMetadata(offset, "")
for tp, offset in offsets.items() # offsets is `Mapping[TP, int]`
# if `assignment` returns `TP` instances (which it does)
# then this builds a `Dict[TP, OffsetAndMetadata]`
if tp in self.assignment()
}
# the following is okay, we can work with `TP` instances
self.tp_last_committed_at.update({tp: now for tp in aiokafka_offsets})
# however the following calls into `aiokafka` and passes the *same* `Dict[TP, OffsetAndMetadata]`.
# It cannot possibly be correct because aiokafka wants `TopicPartition` instances!
await consumer.commit(aiokafka_offsets) # BOOM! EDIT: I'm now thinking that there are cases where the |
I think I finally figured it out after digging deeper into faust-streaming. First of all yes _commit is an internal function according to pythonic convention (prefixed with underscore). You should be careful when using it, although in that case it's documentation here is not optimal and the type hints suggest that faust TP is used here. Now for the initial question, how this all did work anyways:
This means the TopicPartition is never really changed to an faust internal TP when using the aiokafka driver, It's simply typed like one. Why do you want to call Hope this explanation helps to understand the inner workings. And also resolves your question. This is actually not a bug just somewhat bad type hinting and weak ensuring of the correct classes transferred to aiokafka. Plus no docs about this. Edit 1: Actually this is bad wording, it is not badly typed, its the only way we get a coherent way of typing internally. |
That's the thing, I'm not calling That means that something is passing |
Ah okay sorry for this misunderstanding. Looks like if you start in client mode the on_message callback provides Faust TPs. You still didn't share your config how this happens so it's hard to say really. https://github.com/faust-streaming/faust/blob/master/faust/transport/conductor.py#L268 |
Either way it might be a low hanging fruit to ensure aiokafka topic partitions is thrown into the aiokafka lib. |
I'm trying to create a minimal example, but I'm running a 32 hour processing job at the moment, so I don't want to interrupt it. I'll see what I can dig up. Aren't the commits a no-op in client-only mode because the consumer doesn't have a consumer group? |
I guess client only mode would not reach this commit method here as it is intended as dev mode that does not require a kafka but has a simple reply_consumer. Edit: so yes what you said. |
I found a puzzling issue.
Both aiokafka and faust define named tuples for
(topic, partition)
, namelyTopicPartition
andTP
respectively. The faust one doesn't satisfy theisinstance
check in aiokafka'scommit_structure_validate
and so the stack trace below occurs. What I don't understand is how this ever worked. Why do I only see this now? Is this some unusual commit path?Either way, a faust
TP
is not a aiokafkaTopicPartition
according toisinstance
, so this must be a bug.The text was updated successfully, but these errors were encountered: