From 303f989ea85d0e119fafd065df2fcb831adba1b9 Mon Sep 17 00:00:00 2001 From: David Simon Date: Fri, 14 Oct 2022 15:23:13 -0700 Subject: [PATCH] Add caller field --- nplusone/core/listeners.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nplusone/core/listeners.py b/nplusone/core/listeners.py index d933187..eece504 100644 --- a/nplusone/core/listeners.py +++ b/nplusone/core/listeners.py @@ -5,6 +5,7 @@ from collections import defaultdict from nplusone.core import signals +from nplusone.core.stack import get_caller class Rule(object): @@ -39,6 +40,7 @@ class Message(object): def __init__(self, model, field): self.model = model self.field = field + self.caller = get_caller() @property def message(self): @@ -46,6 +48,7 @@ def message(self): label=self.label, model=self.model.__name__, field=self.field, + caller=f"{self.caller.filename}:{self.caller.lineno} in {self.caller.function}", ) def match(self, rules): @@ -57,7 +60,7 @@ def match(self, rules): class LazyLoadMessage(Message): label = 'n_plus_one' - formatter = 'Potential n+1 query detected on `{model}.{field}`' + formatter = 'Potential n+1 query detected on `{model}.{field}` at {caller}' class EagerLoadMessage(Message):