From b0bbc1403988ccec93d0f97ed41bc13bc91270c4 Mon Sep 17 00:00:00 2001 From: Grant Toeppen Date: Thu, 17 Apr 2014 16:04:25 -0700 Subject: [PATCH] version check on django to see how we wrap the CursorDebugWrapper --- django_statsd/patches/db.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/django_statsd/patches/db.py b/django_statsd/patches/db.py index e5bea2b..4806d4c 100644 --- a/django_statsd/patches/db.py +++ b/django_statsd/patches/db.py @@ -9,11 +9,6 @@ def key(db, attr): def __getattr__(self, attr): - """ - The CursorWrapper is a pretty small wrapper around the cursor. - If you are NOT in debug mode, this is the wrapper that's used. - Sadly if it's in debug mode, we get a different wrapper. - """ if django.VERSION < (1, 6) and self.db.is_managed(): # In Django 1.6 you can't put a connection in managed mode self.db.set_dirty() @@ -39,7 +34,16 @@ def wrap_class(base): def patch(): + """ + The CursorWrapper is a pretty small wrapper around the cursor. + If you are NOT in debug mode, this is the wrapper that's used. + Sadly if it's in debug mode, we get a different wrapper for version earlier than 1.6. + """ + # So that it will work when DEBUG = True. - util.CursorDebugWrapper = wrap_class(util.CursorDebugWrapper) + if django.VERSION < (1, 6): + util.CursorDebugWrapper = wrap_class(util.CursorDebugWrapper) + else: + util.CursorDebugWrapper.__getattr__ = __getattr__ # So that it will work when DEBUG = False. util.CursorWrapper.__getattr__ = __getattr__