Skip to content

Commit

Permalink
Add caller field
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMikeSimon committed Oct 14, 2022
1 parent 2f1e25d commit bc4df56
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nplusone/core/listeners.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from nplusone.core.stack import get_caller
import six
import fnmatch
from collections import defaultdict
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

0 comments on commit bc4df56

Please sign in to comment.