Skip to content
Advertisement

FASTAPI Delete Operation giving Internal server error

I have this code for delete operation on a Postgresql DB:

JavaScript

The create and read operations work fine. If I pass an existing or a non-exsiting id to delete, I get a 500 Internal Server error. The row does get deleted from the table though.

If I comment this line deleted_post = cursor.fetchone(), it works okay.

Here is the error traceback:

JavaScript

What really is happening here??

Advertisement

Answer

The DELETE query does not return any results, thus the fetchone() call raises an error. Try adding a RETURNING clause:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement