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

Request stream not working when using Blueprints #1454

Closed
quasarj opened this issue Jan 2, 2019 · 1 comment
Closed

Request stream not working when using Blueprints #1454

quasarj opened this issue Jan 2, 2019 · 1 comment

Comments

@quasarj
Copy link

quasarj commented Jan 2, 2019

Describe the bug
When trying to use Request Streaming in a route that is part of a blueprint, the request.stream object is never set (it is None), unless stream=True has been set on some global route.

Code snippet

from sanic import Sanic
from sanic.response import text
from sanic.views import HTTPMethodView, stream
from sanic import Blueprint

app = Sanic()

# Not sure if using the decorator here is actually
# allowed or useful
@stream
def test(request):
    return text(type(request.stream))


class TestView(HTTPMethodView):
    @stream
    async def get(self, request):
        return text(type(request.stream))


bp = Blueprint("test")
bp.add_route(test, '/')
bp.add_route(TestView.as_view(), '/class')

app.blueprint(bp, url_prefix='/test')

# Adding this line makes request.stream work FOR ALL ROUTES,
# even those from the blueprint!
# app.add_route(test, '/', stream=True)

app.run(host='0.0.0.0', port=8000)

Expected behavior
Expect request.stream to be set.

Environment (please complete the following information):

  • OS: Ubuntu 18.04, RHEL7
  • Version 18.12.0 and master (cea1547)

Additional context
I am trying to sort this out myself, but the interaction between routes appears very complex. I will submit a pull request if I can get it working.

@chenjr0719
Copy link
Member

@quasarj Are you still there?

According to the document, use request stream with Blueprint will look like this:

from sanic import Sanic, Blueprint

bp = Blueprint("test")

@bp.get('/', stream=True)
def test(request):
    return text(type(request.stream))

app.blueprint(bp, url_prefix='/test')
app.run(host='0.0.0.0', port=8000)

If you want to use bp.add_route() with request stream, it seems not working currently because bp.add_route() does not support stream argument. Maybe I can send a PR to make it work.

chenjr0719 added a commit to chenjr0719/sanic that referenced this issue Jan 30, 2019
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