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

Compatibility changes for upcoming flask version 2.3 #493

Merged
merged 8 commits into from
Aug 15, 2022

Conversation

jrast
Copy link
Contributor

@jrast jrast commented Aug 7, 2022

This PR addresses the issues mentioned in #492

@jrast jrast marked this pull request as draft August 7, 2022 12:59
Created a copy of the deprecated JSONEncoder used by flask and use this
as a default for PyJWT. This might break for some installations which
further extended the flask provided JSONEncoder. To get this working
again the extension must be adjusted such that a custom Encoder can be
configured.
@jrast jrast marked this pull request as ready for review August 7, 2022 13:59
@vimalloc
Copy link
Owner

vimalloc commented Aug 7, 2022

Thanks for looking into this!

Another option that might be worth considering is to follow suite with flask and depreciate the json encoder options as part of this extension, and mark that release as requiring flask >= 2.3. But that's just a thought I had when I woke up and without any caffeine so I want to think on it some more 😄

Edit: Should have had my coffee. I didn't look at this closely enough to realize why we have this option, it's to bridge the gap between flask and pyjwt.

@jrast
Copy link
Contributor Author

jrast commented Aug 7, 2022

Actually many other extensions will also run into problems: Flask-SQLALchemy (pallets-eco/flask-sqlalchemy#1068), Flask-Security / Flask-Security-Too (pallets/flask#4711) just to name the few I use most. Flask 2.3 will require quite a bit of changes in extensions as so many things will be removed / restructured / change. Maybe it's worth to keep an eye on other extensions and see how they handle the issues.

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added notes on some little canonicalization things

flask_jwt_extended/utils.py Outdated Show resolved Hide resolved
flask_jwt_extended/config.py Outdated Show resolved Hide resolved
flask_jwt_extended/config.py Outdated Show resolved Hide resolved
Copy link
Owner

@vimalloc vimalloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this took me so long to look at, it's been a crazy week over here.

flask_jwt_extended/utils.py Outdated Show resolved Hide resolved
flask_jwt_extended/config.py Outdated Show resolved Hide resolved
@jrast
Copy link
Contributor Author

jrast commented Aug 12, 2022

I'm right now working on this to fix the reviewd changes. Don't expect the optimal solution but I try to at least reach these goals:

  • Be compatible with Flask < 2.2 where flask.json.JSONEncoder exists
  • Be forward compatible with Flask >= 2.2 where the JSONEncoder generates deprecation warnings and be prepared once the decoder is removed.

I think this would be a good starting point to going further.

@vimalloc
Copy link
Owner

I'm right now working on this to fix the reviewd changes. Don't expect the optimal solution but I try to at least reach these goals:

* Be compatible with Flask < 2.2 where flask.json.JSONEncoder exists

* Be forward compatible with Flask >= 2.2 where the JSONEncoder generates deprecation warnings and be prepared once the decoder is removed.

I think this would be a good starting point to going further.

Sounds great to me! I'll be around to help this get merged and a new release cut, and then digging into a more optimal solution can happen after. Thanks for your work on this!! 🥳 👍

@jrast
Copy link
Contributor Author

jrast commented Aug 12, 2022

I pushed some new code:

  • Works with flask <2.2 and flask >= 2.2
  • Does currently not respect the flask.json_provider_class setting and uses conditional imports to get a valid encoder (see json_encoder.py)
  • Coverage Test might fail as coverage is only run with one flask version and misses the conditional import code for the other flask version.

@jrast
Copy link
Contributor Author

jrast commented Aug 12, 2022

Damn, now you where faster than me... I was working on a simmilar idea, with the additional benefit that the new app.json_provider_class was respected in case of Flask >= 2.2....

@vimalloc
Copy link
Owner

Damn, now you where faster than me... I was working on a simmilar idea, with the additional benefit that the new app.json_provider_class was respected in case of Flask >= 2.2....

Sorry, didn't mean to step on your toes here, just had some time so figured I would take a stab at it! If you have a different idea please feel free to revert that last commit and push your stuff up!

@jrast
Copy link
Contributor Author

jrast commented Aug 12, 2022

No problem at all! Nice to see other motivated devs working on this! Things in my latest commit:

  • respect app.json_provider_class. However this requires some hacky way to generate a JSONEncoder class on the fly...
  • moved from json_encoder.py to internal_utils.py
  • Documented the stuff I did.

If this sound reasonable I will push the changes. I have also updated tox.ini to test with flask < 2.2 and flask > 2.2, I can also push this if you want.

@vimalloc
Copy link
Owner

No problem at all! Nice to see other motivated devs working on this! Things in my latest commit:

* respect `app.json_provider_class`. However this requires some hacky way to generate a JSONEncoder class on the fly...

* moved from `json_encoder.py` to `internal_utils.py`

* Documented the stuff I did.

If this sound reasonable I will push the changes. I have also updated tox.ini to test with flask < 2.2 and flask > 2.2, I can also push this if you want.

That would be awesome! Thank you for the very thorough work you're doing on this!! 👍

Respect the json_provider_class when available and stay compatible
with flask < 2.2. Extended tox configuration to also test with flask < 2.2.
@jrast
Copy link
Contributor Author

jrast commented Aug 12, 2022

Ok, I force-pushed my changes. Let's see what you think.

flask_jwt_extended/view_decorators.py Outdated Show resolved Hide resolved
flask_jwt_extended/internal_utils.py Outdated Show resolved Hide resolved
@vimalloc
Copy link
Owner

Looks good. Left one small thought that I think is probably worth changing just to be safe, but overall I like the approach. Thanks!

jrast added 3 commits August 12, 2022 22:53
The code in question was a runtime check which is no longer necesary.
- Added tests to check the config.json_encoder
- Don't create the JSONEncoder class on the fly, instead get the
  JSON provider class at runtime.
Copy link

@Seluj78 Seluj78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ! Can't wait to get this release :D

Copy link
Owner

@vimalloc vimalloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vimalloc vimalloc merged commit 88a628e into vimalloc:master Aug 15, 2022
@Seluj78
Copy link

Seluj78 commented Aug 15, 2022

Amazing ! Could you release this soon ? :)

@vimalloc
Copy link
Owner

It's up as version 4.4.4. Cheers!

@jrast jrast deleted the flask23-compat branch August 15, 2022 20:03
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

Successfully merging this pull request may close these issues.

4 participants