runnel
runnel copied to clipboard
KeyError: 'RUNNEL_TESTING'
Running simple example for middlewares:
from datetime import datetime
from runnel import App, Record, Events, Middleware
app = App(name="myapp", redis_url="redis://127.0.0.1")
class Order(Record):
order_id: int
created_at: datetime
amount: int
class Printer(Middleware):
async def handler(self, parent: Events, **kwargs):
async for x in parent:
print(x)
yield x
orders = app.stream("orders", record=Order, partition_by="order_id")
@app.processor(orders, middleware=[Printer()])
async def printer(events: Events):
async for order in events.records():
pass
error stack
Traceback (most recent call last):
File "/Users/colch/Work/py-word-counter/.venv/lib/python3.9/site-packages/runnel/runner.py", line 157, in consumer
await tg.cancel_scope.cancel()
File "/Users/colch/Work/py-word-counter/.venv/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 438, in __aexit__
raise exceptions[0]
File "/Users/colch/Work/py-word-counter/.venv/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 466, in _run_wrapped_task
await func(*args)
File "/Users/colch/Work/py-word-counter/app.py", line 26, in printer
async for order in events.records():
File "/Users/colch/Work/py-word-counter/.venv/lib/python3.9/site-packages/runnel/events.py", line 175, in iter
async for x in agen:
File "/Users/colch/Work/py-word-counter/.venv/lib/python3.9/site-packages/runnel/middleware/deserialize.py", line 11, in handler
async for x in parent:
File "/Users/colch/Work/py-word-counter/.venv/lib/python3.9/site-packages/runnel/middleware/ack.py", line 11, in handler
async for x in parent:
File "/Users/colch/Work/py-word-counter/app.py", line 17, in handler
print(x)
File "/Users/colch/Work/py-word-counter/.venv/lib/python3.9/site-packages/runnel/types.py", line 82, in __repr__
if os.environ["RUNNEL_TESTING"] == "1":
File "/usr/local/Cellar/[email protected]/3.9.1_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/os.py", line 679, in __getitem__
raise KeyError(key) from None
KeyError: 'RUNNEL_TESTING'
Exporting env variable RUNNEL_TESTING fixes this, indeed. But I suppose, os.environ["RUNNEL_TESTING"] should be os.environ.get("RUNNEL_TESTING"), right?
In my opnion, It's better to use "os.getevn" rather than "os.environ".