miLibris / flask-rest-jsonapi

Flask extension to build REST APIs around JSONAPI 1.0 specification.
http://flask-rest-jsonapi.readthedocs.io
MIT License
597 stars 153 forks source link

Assign check_headers decorator as class declaration to prevent Recursion Error #28

Closed philof closed 7 years ago

philof commented 7 years ago

Using a class decoration in Flask assigns the decorator at instantiation rather than each request, which @kypsibir pointed out.

Every request is now stable.

--------------------------------------------------------------------------------
127.0.0.1 - - [08/Apr/2017 15:55:06] "GET /persons HTTP/1.1" 200 -
--------------------------------------------------------------------------------
PATH: '/persons'
         4749 function calls (4673 primitive calls) in 0.017 seconds
coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.008%) to 95.965% when pulling 81a2c85226fac08f5ffebf1a8a906fcf7c8fbe21 on philof:master into 8597f8c89a73bcc0d331155a5c4b38801026d2b6 on miLibris:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.008%) to 95.965% when pulling 81a2c85226fac08f5ffebf1a8a906fcf7c8fbe21 on philof:master into 8597f8c89a73bcc0d331155a5c4b38801026d2b6 on miLibris:master.

philof commented 7 years ago

27

akira-dev commented 7 years ago

I can't do this because if you set decorators in the end class this decorator list in the base resource will be overridden so check_headers will never be performed. I will make a fix for this today with metaclass to construct the class dynamically instead of using the constructor the instance.

philof commented 7 years ago

That use case is already tested in the unit tests. Test_wrong_accept_headers hits PersonList which has custom get and post decorators.

akira-dev commented 7 years ago

New release is available on pypi with bug fix of this issue

akira-dev commented 7 years ago

Thank you very much for your contribution