FastApi-RESTful icon indicating copy to clipboard operation
FastApi-RESTful copied to clipboard

[BUG] Risk of data loss

Open skion opened this issue 3 years ago • 2 comments

Describe the bug

FastApi-RESTful appears to commit-after-yield in a FastAPI dependency, which most likely creates risk of data loss since when a commit raises an exception a positive HTTP response has already been returned to the user.

To Reproduce Steps to reproduce the behavior:

  1. Raise an exception after the yield.
  2. Observe the HTTP response is not affected

Expected behavior

When a database transaction cannot be committed, a positive HTTP response should never be sent.

Environment:

  • FastAPI version 0.88.0
  • Python version 3.10.7

Additional context

skion avatar Jan 17 '23 21:01 skion

I will check upon this issue, can you address the file or add a small snippet that would not require active DB to execute?

yuval9313 avatar Jan 20 '23 16:01 yuval9313

It was made to allow "auto commits" to be performed, any ideas on how to treat this otherwise properly? I don't want to break the way it is being used currently But I figure there is no other choice.

Do you still use the middleware method? how would u suggest it being implemented into this lib?

yuval9313 avatar Aug 09 '23 05:08 yuval9313