4

I'm using SQLAlchemy 1.3.22 and doing a bulk insert of thousands of rows. If there is a database error the SQLAlchemy ProgrammingError exception that gets raised in the console prints the query and all of the values. Even though I'm chunking the inserts this still prints an incredible amount of garbage to the console which buries the actual error message many thousands of lines up in the console, is time-consuming, and can even slow/freeze the IDE until its done.

I tried searching to see if there is any way to control this output -- I still want to see the exceptions and error message but just limit the extra print of the SQL and its thousands of arguments (it prints the long VALUES clause and all of the stuff it would substitute into those placeholders).

Dividing into smaller chunks is not a good solution since it negatively impacts performance and doesn't really solve the problem unless the chunks are very small. I can catch the exception and try to re-raise it with a truncated message, but that feels hacky as well. Hoping I'm just missing a way to control the error format...

totalhack
  • 2,298
  • 17
  • 23

0 Answers0