diff --git a/nplusone/core/listeners.py b/nplusone/core/listeners.py index d933187..a8fe8f0 100644 --- a/nplusone/core/listeners.py +++ b/nplusone/core/listeners.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from nplusone.core.stack import get_caller import six import fnmatch from collections import defaultdict @@ -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):