Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caller field #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nplusone/core/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import defaultdict

from nplusone.core import signals
from nplusone.core.stack import get_caller


class Rule(object):
Expand Down Expand Up @@ -39,13 +40,15 @@ class Message(object):
def __init__(self, model, field):
self.model = model
self.field = field
self.caller = get_caller()

@property
def message(self):
return self.formatter.format(
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):
Expand All @@ -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):
Expand Down