# Buggy code
async def _process(self, query: str):
    username, subject, client_id, access_token, refresh_token, args = _parse_query(
        query
    )
    logger.debug(f"user: {username}, client: {client_id}")
    logger.debug(args)
    app_state, user_state, client_state = self._state
    args_state: dict = unmarshal(args)
    events_state: Optional[dict] = args_state.get("", None)
    if events_state:
        events_state = {k: Expando(v) for k, v in events_state.items()}
        del args_state[""]
    q = Q(
        site=self._site,
        mode=self._mode,
        username=username,
        client_id=client_id,
        route=self._route,
        app_state=app_state,
        user_state=_session_for(user_state, username),
        client_state=_session_for(client_state, client_id),
        auth=Auth(username, subject, access_token, refresh_token),
        args=Expando(args_state),
        events=Expando(events_state),
    )
    # noinspection PyBroadException,PyPep8
    try:
        await self._handle(q)
    except:
        logger.exception("Unhandled exception")
        # noinspection PyBroadException,PyPep8
        try:
            q.page.drop()
            # TODO replace this with a custom-designed error display
            q.page["__unhandled_error__"] = markdown_card(
                box="1 1 -1 -1",
                title="Error",
                content=f"```\n{traceback.format_exc()}\n```",
            )
            await q.page.save()
        except:
            logger.exception("Failed transmitting unhandled exception")


# Traceback (AttributeError)
ERROR:    Exception in ASGI application
Traceback (most recent call last):
File "/home/dott/Projects/q-model-validation/venv/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 389, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/home/dott/Projects/q-model-validation/venv/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
return await self.app(scope, receive, send)
File "/home/dott/Projects/q-model-validation/venv/lib/python3.8/site-packages/h2o_wave/server.py", line 323, in __call__
await self._app.app(scope, receive, send)
File "/home/dott/Projects/q-model-validation/venv/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__
await route.handle(scope, receive, send)
File "/home/dott/Projects/q-model-validation/venv/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle
await self.app(scope, receive, send)
File "/home/dott/Projects/q-model-validation/venv/lib/python3.8/site-packages/starlette/routing.py", line 44, in app
await response(scope, receive, send)
File "/home/dott/Projects/q-model-validation/venv/lib/python3.8/site-packages/starlette/responses.py", line 152, in __call__
await self.background()
File "/home/dott/Projects/q-model-validation/venv/lib/python3.8/site-packages/starlette/background.py", line 18, in __call__
await self.func(*self.args, **self.kwargs)
File "/home/dott/Projects/q-model-validation/venv/lib/python3.8/site-packages/h2o_wave/server.py", line 248, in _process
events_state = {k: Expando(v) for k, v in events_state.items()}
AttributeError: 'bool' object has no attribute 'items'

# Fixed code
async def _process(self, query: str):
    username, subject, client_id, access_token, refresh_token, args = _parse_query(
        query
    )
    logger.debug(f"user: {username}, client: {client_id}")
    logger.debug(args)
    app_state, user_state, client_state = self._state
    args_state: dict = unmarshal(args)
    events_state: Optional[dict] = args_state.get("", None)
    if isinstance(events_state, dict):
        events_state = {k: Expando(v) for k, v in events_state.items()}
        del args_state[""]
    q = Q(
        site=self._site,
        mode=self._mode,
        username=username,
        client_id=client_id,
        route=self._route,
        app_state=app_state,
        user_state=_session_for(user_state, username),
        client_state=_session_for(client_state, client_id),
        auth=Auth(username, subject, access_token, refresh_token),
        args=Expando(args_state),
        events=Expando(events_state),
    )
    # noinspection PyBroadException,PyPep8
    try:
        await self._handle(q)
    except:
        logger.exception("Unhandled exception")
        # noinspection PyBroadException,PyPep8
        try:
            q.page.drop()
            # TODO replace this with a custom-designed error display
            q.page["__unhandled_error__"] = markdown_card(
                box="1 1 -1 -1",
                title="Error",
                content=f"```\n{traceback.format_exc()}\n```",
            )
            await q.page.save()
        except:
            logger.exception("Failed transmitting unhandled exception")