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

Flask teardown_request vs after_request #432

Closed
orenmazor opened this issue Mar 12, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@orenmazor
Copy link

commented Mar 12, 2019

I was reading through the code and this bit jumped out at me:

https://github.com/ponyorm/pony/blob/orm/pony/flask/__init__.py#L24

The flask documentation says that a teardown_request hook can be called even when no requests have been processed(http://flask.pocoo.org/docs/1.0/api/#flask.Flask.teardown_request). This means that the pony integration will raise an error, as no db_session has been entered.

I think you should either:

  1. switch this code to use an after_request, or
  2. have the teardown request function not raise an error if a session doesn't exist.

I hit this flow because the Flask test_request_context will call the teardown function in tests even when no requests are called.

thoughts? I can adjust my currently open PR to reproduce this in #431

@orenmazor orenmazor referenced this issue Mar 12, 2019

Open

Flask test #431

@sashaaero

This comment has been minimized.

Copy link
Member

commented Mar 15, 2019

Hello, @orenmazor. Thanks for reporting and clarifying.
You are right, we should ignore cases when there is no db_session in requrest object.

@sashaaero sashaaero closed this in 5618cce Mar 31, 2019

kozlovsky added a commit that referenced this issue Apr 20, 2019

PonyORM release 0.7.10 (2019-04-20)
# Bugfixes

* Python3.7 and PyPy decompiling fixes
* Fix reading NULL from Optional nullable array column
* Fix handling of empty arrays in queries
* #415: error message typo
* #432: PonyFlask - request object can trigger teardown_request without real request
* Fix GROUP CONCAT separator for MySQL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.