@@ -711,13 +711,15 @@ async def commit(self, offsets: Mapping[TP, int]) -> bool:
711711 async def _commit (self , offsets : Mapping [TP , int ]) -> bool :
712712 consumer = self ._ensure_consumer ()
713713 now = monotonic ()
714+ commitable_offsets = {
715+ tp : offset for tp , offset in offsets .items () if tp in self .assignment ()
716+ }
714717 try :
715718 aiokafka_offsets = {
716- tp : OffsetAndMetadata (offset , "" )
717- for tp , offset in offsets .items ()
718- if tp in self .assignment ()
719+ ensure_aiokafka_TP (tp ): OffsetAndMetadata (offset , "" )
720+ for tp , offset in commitable_offsets .items ()
719721 }
720- self .tp_last_committed_at .update ({tp : now for tp in aiokafka_offsets })
722+ self .tp_last_committed_at .update ({tp : now for tp in commitable_offsets })
721723 await consumer .commit (aiokafka_offsets )
722724 except CommitFailedError as exc :
723725 if "already rebalanced" in str (exc ):
@@ -1621,3 +1623,17 @@ def credentials_to_aiokafka_auth(
16211623 }
16221624 else :
16231625 return {"security_protocol" : "PLAINTEXT" }
1626+
1627+
1628+ def ensure_aiokafka_TP (tp : TP ) -> _TopicPartition :
1629+ """Convert Faust ``TP`` to aiokafka ``TopicPartition``."""
1630+ return (
1631+ tp
1632+ if isinstance (tp , _TopicPartition )
1633+ else _TopicPartition (tp .topic , tp .partition )
1634+ )
1635+
1636+
1637+ def ensure_aiokafka_TPset (tps : Iterable [TP ]) -> Set [_TopicPartition ]:
1638+ """Convert set of Faust ``TP`` to aiokafka ``TopicPartition``."""
1639+ return {ensure_aiokafka_TP (tp ) for tp in tps }
0 commit comments