Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    András Mózes
    @mozesa
    Hello! @pgjones you mentioned earlier that there is a plan for async for message in websocket.receive_json(). I just would like to reinforce that it would be a nice feature :smile:
    Anil Waghmare
    @anilmwr
    Hi All, I am trying to test an Angular app with Quart, it works fine when loaded for the first time, but if I rebuild the Angular app and copy new files to /static and /templates directories, I still see the older version of the app in Browser. If I force reload by disabling cache, the modified template content under /templates is not picked up. I have no option other than killing the Quart app instance and restarting it, after which it correctly picks newly built template file contents. How to resolve this template caching problem? Thanks!
    Phil Jones
    @pgjones
    Are you using 0.14.1? This should be fixed by pgjones/quart@cbc72c5
    Anil Waghmare
    @anilmwr
    I am on Python 3.9.1 and Quart version is '0.14.1'.
    Phil Jones
    @pgjones
    With debug=True?
    Anil Waghmare
    @anilmwr
    Where should I specify debug=True? I am serving my app using below statement:
    hypercorn.asyncio.serve(app, quart_config)
    Phil Jones
    @pgjones
    app.debug = True - this is for development right?
    Also app.templates_auto_reload = Trueor app.config["TEMPLATES_AUTO_RELOAD"] = True
    Anil Waghmare
    @anilmwr
    Yes, for development, with above lines added, it is loading updated template. Thanks a lot!
    Phil Jones
    @pgjones
    :+1:
    (Only need one of the above)
    McSinyx
    @McSinyx:matrix.org
    [m]
    about quart-trio, is there any recommendation regarding testing TooSlowError with the embeded client
    Dave Hirschfeld
    @dhirschfeld
    :wave: hi @mozesa, before I go down the rabbit-hole - did you ever get hypercorn working with structlog?
    Phil Jones
    @pgjones
    @McSinyx:matrix.org something like,
    async with test_client.request(...) as connection:
        connection.send(b"data")
        await trio.sleep(A_LONG_TIME)
    assert connection.as_response().status_code == 408
    Not tested, but I think it will work...
    McSinyx
    @McSinyx:matrix.org
    [m]
    thanks, i'll try
    Tigran Tch
    @NargiT
    hello is there a way to prefix all routes without affecting the code source?
    I saw that we can use SCRIPT_NAME in wsgi spec, and I was wondering if there is an equivalent for asgi with hypercorn or uvicorn for example.
    xarvos
    @xarvos:matrix.org
    [m]
    I suppose you can set config APPLICATION_ROOT
    Phil Jones
    @pgjones
    The ASGI root_path should work for this, could you try with hypercorn and see if it narrows down the bug to uvicorn or Quart?
    András Mózes
    @mozesa
    @dhirschfeld Hello! No, I haven't checked, but it is on the todo-list. I would like to use structlog and I would like to log accesses and errors. But it seems to me only former can be customised.
    Phil Jones
    @pgjones
    @mozesa they both can be, you should be able to customise this
    András Mózes
    @mozesa
    @pgjones Cool :smile:
    András Mózes
    @mozesa
    @dhirschfeld
    logger = (structlog.stdlib.get_logger()).bind()
    
    config = hypercorn.Config.from_mapping(
        bind=[f"0.0.0.0:{port}"],
        accesslog=None,
        errorlog=None,
        worker_class="trio",
    )
    config.accesslog = logger  # b/c logger is not isisnstance of logging.Logger
    Dave Hirschfeld
    @dhirschfeld
    Thanks @mozesa & @pgjones! I'll give that a go...
    Jorge Escobar
    @esfoobar

    Hi @pgjones -- I've been dealing with a very weird issue with the SSE application I mentioned earlier. The whole code is here: https://github.com/esfoobar/quart-feed. But what's happening is that once I get into the SSE page (the home page) and I reload several times manually, I eventually get to this error:

    ages/aiomysql/cursors.py", line 457, in _query
    quartfeed_web_1 |     await conn.query(q)
    quartfeed_web_1 |   File "/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/aiomysql/connection.py", line 428, in query
    quartfeed_web_1 |     await self._read_query_result(unbuffered=unbuffered)
    quartfeed_web_1 |   File "/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/aiomysql/connection.py", line 622, in _read_query_result
    quartfeed_web_1 |     await result.read()
    quartfeed_web_1 |   File "/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/aiomysql/connection.py", line 1105, in read
    quartfeed_web_1 |     first_packet = await self.connection._read_packet()
    quartfeed_web_1 |   File "/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/aiomysql/connection.py", line 561, in _read_packet
    quartfeed_web_1 |     packet_header = await self._read_bytes(4)
    quartfeed_web_1 |   File "/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/aiomysql/connection.py", line 598, in _read_bytes
    quartfeed_web_1 |     data = await self._reader.readexactly(num_bytes)
    quartfeed_web_1 |   File "/usr/local/lib/python3.8/asyncio/streams.py", line 723, in readexactly
    quartfeed_web_1 |     await self._wait_for_data('readexactly')
    quartfeed_web_1 |   File "/usr/local/lib/python3.8/asyncio/streams.py", line 503, in _wait_for_data
    quartfeed_web_1 |     raise RuntimeError(
    quartfeed_web_1 | RuntimeError: readexactly() called while another coroutine is already waiting for incoming data

    Any ideas why this is happening?

    Phil Jones
    @pgjones
    Hmm, looks like aiomysql needs a lock or to use a connection pool?
    Jorge Escobar
    @esfoobar
    That's what I thought, but I tried returning a pool connection here: https://github.com/esfoobar/quart-feed/blob/master/db.py#L16-L24
    However that conn2 object is different from the engine.acquire() here: https://github.com/esfoobar/quart-feed/blob/master/db.py#L14
    Do you know of a snippet that has a pool that's compatible with SqlAlchemy?
    Jorge Escobar
    @esfoobar
    I'm using SQLAlchemy Core so that pool implementation doesn't work
    Tigran Tch
    @NargiT

    The ASGI root_path should work for this, could you try with hypercorn and see if it narrows down the bug to uvicorn or Quart?

    root_path does not add in the url the path. Do I have to setup a proxy and rewrite url in order to redirect to "/" ?

    Phil Jones
    @pgjones
    This may be a bug, I'll try find some time to investigate
    @esfoobar have you tried using Databases?
    Jorge Escobar
    @esfoobar
    I have read about it -- I can try implementing -- I just wish I knew it was going to fix the issue
    But I appreciate your help @pgjones
    Phil Jones
    @pgjones
    I use it, and it seems to setup connection pools
    Jorge Escobar
    @esfoobar
    Awesome, I'll see if I can hook it up quickly and will let you know
    Phil Jones
    @pgjones
    @NargiT I think ASGI servers have a bug, django/asgiref#229
    Jorge Escobar
    @esfoobar
    @pgjones I'm SO HAPPY! The move to databases made all the difference. It's now rock solid, reloading as fast I can throws no errors!
    And the SSE experience feels near-instantaneous, thanks!
    Phil Jones
    @pgjones
    :+1:
    Nice
    Phil Jones
    @pgjones
    @NargiT The Hypercorn master branch should work as you expect with the root-path if you can try it out
    Jorge Escobar
    @esfoobar

    Hi @pgjones , I am now seeing a new error on tests that I hadn't seen before.

    In my conftest I have the following fixture:

    @pytest.fixture(scope="module")
    async def create_test_app(create_db):
        app = create_app(**create_db)
        await app.startup()
        yield app
        await app.shutdown()

    It seems app.shutdown() is throwing this error:

    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/six.py:703:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/six.py:703: in reraise
        raise value
    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/six.py:703: in reraise
        raise value
    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/pytest_asyncio/plugin.py:93: in finalizer
        loop.run_until_complete(async_finalizer())
    /usr/local/lib/python3.8/asyncio/base_events.py:616: in run_until_complete
        return future.result()
    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/pytest_asyncio/plugin.py:85: in async_finalizer
        await gen_obj.__anext__()
    conftest.py:67: in create_test_app
        await app.shutdown()
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    self = <quart.app.Quart object at 0x7f9947998dc0>
    
        async def shutdown(self) -> None:
            for func in self.after_serving_funcs:
                await func()
            app_ctx = _app_ctx_stack.top
    >       await app_ctx.pop(None)
    
    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/quart/app.py:2155: AttributeError
    ================================================================ short test summary info =================================================================
    ERROR relationship/test_relationship.py::test_succesful_follow - AttributeError: 'NoneType' object has no attribute 'pop'
    ERROR user/test_user.py::test_profile_edit - AttributeError: 'NoneType' object has no attribute 'pop'

    Any ideas what is going on?

    I'm using:

    pytest = "==6.2.1"
    pytest-asyncio = "==0.14.0"
    On the application.py I have these:
        @app.before_serving
        async def create_db_conn():
            database = await db_connection()
            await database.connect()
            app.dbc = database
    
        @app.after_serving
        async def close_db_conn():
            await app.dbc.disconnect()
    Phil Jones
    @pgjones
    It should work again if you use master, or if you utilise the test_app