Django querysets evaluated in Raven exception collector?

I noticed something very interesting with Raven/Sentry. It seems that when we have an exception, Raven will try to serialize locals and such in the current stack frame, to send to Sentry.

If some of those variable happens to be a Django queryset, it will call repr on it, which triggers an actual database query. The way we found this was that we were originally trying to track down some expensive queries in our application, and added some logging of the stacktrace on DB queries. We were seeing mysterious queries originated from a Raven code path.

Has anyone else run into this or something similar? Happy to share more info if it helps.

System details:

  • Raven 6.1.0
  • Django 1.9, Python 2.7