turn off SQL logging while keeping settings.DEBUG?

前端 未结 4 693
生来不讨喜
生来不讨喜 2020-12-14 01:31

Django logs SQL operations to an internal buffer (whether logging to file or not) when settings.DEBUG=True. Because I have long-running process that does a lot of DB operat

4条回答
  •  感情败类
    2020-12-14 02:10

    This worked for me (at least for Django 1.3.1):

    from django.db import connection
    connection.use_debug_cursor = False
    

    I've found that variable inspecting Django source code (it is not documented), the relevant lines are found in django/db/backends/__init__.py (BaseDatabaseWrapper class):

    def cursor(self):
        if (self.use_debug_cursor or
            (self.use_debug_cursor is None and settings.DEBUG)):
            cursor = self.make_debug_cursor(self._cursor())
        else:
            cursor = util.CursorWrapper(self._cursor(), self)
        return cursor
    

提交回复
热议问题