Writing into Table with Stream.take() not allowed

Aperta
#497 15 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
18/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

The error is raised in partition_for_key in faust/tables/base.py, reached from on_key_set in faust/tables/table.py when a table key is set inside an agent. Run the reproduction from the issue against a local Kafka and read how the stream context is tracked around stream.take(). Done means either the write succeeds inside take() or the maintainers document the intended pattern. The thread is old and the approach is undecided, so confirm direction before coding.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Steps to reproduce

When using the Stream.take() function I can not write into a Table but get the error Cannot modify table key from outside of stream iteration.

Can I just not write to tables when using take?

Example:

from faust import App

app = App(id="take-error-example")

topic = app.topic('orders')
table = app.Table('orders')

@app.agent(topic)
async def consumer(stream):
    async for values in stream.take(1):
        for value in values:
            table["key"] = "some value"
            yield value

Expected behavior

The key value pair should be written into the Table

Actual behavior

File ".../python3.10/site-packages/mode/utils/collections.py", line 652, in __setitem__
    self.on_key_set(key, value)
  File ".../python3.10/site-packages/faust/tables/table.py", line 77, in on_key_set
    fut = self.send_changelog(self.partition_for_key(key), key, value)
  File ".../python3.10/site-packages/faust/tables/base.py", line 314, in partition_for_key
    raise TypeError(
TypeError: Cannot modify table key from outside of stream iteration

Versions

  • Python version: 3.10.6
  • Faust version: 0.10.11
  • Operating system: MacOS 13
Lingua principale
Python
Stelle
1.9k
Fork
205
Merge medio
2h 2m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di faust-streaming/faust

Tutte le issue di faust-streaming/faust

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.