-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
updated to work with flask 2.2+ #183
Conversation
Replaced _request_ctx_stack.top with request_ctx per https://github.com/pallets/flask/pull/4682/files
Hi, I'm using the currently released version of DTB in a Flask 2.2+ app and it's working here. Did you encounter an error? |
@nickjj, hey, no, no errors, just the depreciation warning that in flask 2.3 the |
Ah right. This project currently has What do you think? |
Yeah, that's an idea. From the flask PR, they said this was existing all along, but I'm not sure what version of flask it was really added. We could something like this: Probably there is a cleaner way? |
I didn't fully test this but if you put this into a Python interpreter it works. The import flask
from packaging import version
version.parse(flask.__version__) >= version.parse("2.2.0") That condition is what you could do to require a specific package from Flask. |
How this look @nickjj ? The tests run fine w/ tox, but not the stylecheck. It looks like the tox file needs updated? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but @nickjj can you take a quick look too? If looks good to you, please merge...
if version_builder.parse(flask.__version__) >= version_builder.parse("2.2.0"): | ||
req = request_ctx.request | ||
else: | ||
req = _request_ctx_stack.top.request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, you can't just alias the package import (from flask.globals import _request_ctx_stack as request_ctx
) because the object's API changed as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep I discovered that after the comment too.
from flask import Blueprint, current_app, request, g, send_from_directory, url_for | ||
from flask.globals import _request_ctx_stack | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't work much with Python these days, but I thought style guides would suggest this as only 1 blank line rather than 2 between the other imports (or even no blank lines since it's just a conditional import and not a distinct function)? Which does pycodestyle
prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally black
prefers 2 lines between functions but there's no set rule for spaces between imports and your first expressions. This is also a fun one because it's technically handling an import but it's also an expression.
Do you have a preference? I don't have pycodestyle
installed locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm cool either way!
I'm generally ok with it as a concept. I'm not loving repeating that version check twice but this also feels like a spot where if it were refactored and made into a general version compare function it might make things less readable in the end. Do you want to wait for the author of the PR to potentially remove that 1 empty line before merging it @jeffwidman? |
Thanks again! |
Replaced _request_ctx_stack.top with request_ctx per https://github.com/pallets/flask/pull/4682/files