Skip to content
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

KeyError: 'RUNNEL_TESTING' #10

Open
ColCh opened this issue Jan 5, 2021 · 1 comment
Open

KeyError: 'RUNNEL_TESTING' #10

ColCh opened this issue Jan 5, 2021 · 1 comment

Comments

@ColCh
Copy link

ColCh commented Jan 5, 2021

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?

@StevenBanama
Copy link

In my opnion, It's better to use "os.getevn" rather than "os.environ".

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

No branches or pull requests

2 participants