python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.16k stars 335 forks source link

Getting error 500 instead of 401 from jwt after upgrading to 1.0.5 #512

Closed m-melis closed 1 year ago

m-melis commented 1 year ago

Hi, we are getting problems with exceptions not correctly propagated after upgrading to 1.0.5. In particular, we are using jwt-extended, and now getting error 500 instead of 401 when a jwt token is expired. I'm sure however that this problem may happen in other cases too.

Possibly due to this change? https://github.com/python-restx/flask-restx/commit/d638a541d4dcd0402936b3e9dd3dc0d8375bd493#diff-203b671c977f57e9c85560213f75908dabf24167ffa3b57360879486bc84e487

Thanks, Marco

P.S.: thanks @peter-doggart for taking care of this amazing project!

peter-doggart commented 1 year ago

Hi @m-melis - Thanks for raising this. You are correct, I have accidentally introduced a change here. I assumed (wrongly) that current_app.propagate_exceptions just read the property, but looking at the flask source it actually does some checks to see if debug or test mode is enabled too:

        rv = self.config["PROPAGATE_EXCEPTIONS"]
        if rv is not None:
            return rv
        return self.testing or self.debug

I will move this change into flask-restx at the weekend, which should hopefully revert the behaviour to how it was previously. However, in the short term you can control this setting directly in your own application if you need by setting the configuration field:

app = Flask(__name__)
app.config["PROPAGATE_EXCEPTIONS"] = True
peter-doggart commented 1 year ago

@m-melis

This should now be fixed in master if you want to test it fixes your issue? You can install directly using pip:

pip install git+https://github.com/python-restx/flask-restx.git

Otherwise, I will probably release this tomorrow! I'm going to make some changes to add in python 3.11 support first.

Pete

m-melis commented 1 year ago

Thanks! I'll confirm after the weekend 👍🏽

m-melis commented 1 year ago

@peter-doggart Testing current 1.0.6-dev version and the problem seems to be gone.

Closing this, thanks!

peter-doggart commented 1 year ago

@m-melis Thanks for testing. This is now released as 1.0.6 on PyPi. :+1: