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

docs show test_request_context data setting request args. #4964

Closed
ablacklama opened this issue Feb 8, 2023 · 5 comments
Closed

docs show test_request_context data setting request args. #4964

ablacklama opened this issue Feb 8, 2023 · 5 comments
Labels

Comments

@ablacklama
Copy link

The data arg in app.test_request_context() is shown in the docs to set the request args, but as far as I can tell it isn't doing so.

I ran a minimal version of the example in the docs

from flask import Flask, request
app = Flask("test_app")
def generate_report():
    format = request.args.get('format')
    print(format) # --> None

with app.test_request_context(
        '/make_report/2017', data={'format': 'short'}):
    generate_report()

The docs use request.args.get('format') which certainly implies that the data argument set there should set a request arg. But the code above just prints None.

I assume that data in the example should be changed to query_string and that the query_string arg should be added to the docs here

Environment:

  • Python version: 3.10 and 3.11
  • Flask version: 2.2.2
@ablacklama ablacklama changed the title test_request_context data isn't setting request args. docs show test_request_context data setting request args. Feb 8, 2023
@davidism davidism added the docs label Feb 8, 2023
@ablacklama
Copy link
Author

ablacklama commented Feb 10, 2023

Thanks for the fix, can you also add it as a parameter to the test_request_context function doc?

@davidism
Copy link
Member

From the docs you just linked:

Takes the same arguments as Werkzeug’s EnvironBuilder, with some defaults from the application. See the linked Werkzeug docs for most of the available arguments. Flask-specific behavior is listed here.

@ablacklama
Copy link
Author

I'm aware but it seems very unintuitive based on the other arguments that are listed there. It's very easy to miss the part where it says that most arguments are listed in the linked doc. And personally, whenever docs link to other third party docs for additional arguments I always assume it's for more advanced arguments that I probably don't need to touch unless I'm really doing something funky.

I know we want to avoid listing arguments here that should be defined in (and only in) the Werkzeug docs. But perhaps a "query_string — see Werkzeug docs" would be appropriate? Or maybe saying "see the linked Werkzeug docs for most of the available arguments such as ..., ..., Or ..."?

I totally get it if you don't think that's appropriate though.

@davidism
Copy link
Member

davidism commented Feb 10, 2023

I always assume

Don't do this, problem solved ;-) There are way, way more arguments than this one, it's not special.

@ablacklama
Copy link
Author

Fair enough. And the confusion I had really stemmed from the bad example that you fixed.

Cheers!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants