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

NameError: name 'silk_profile' is not defined #172

Closed
coderbhupendra opened this issue Mar 19, 2017 · 5 comments
Closed

NameError: name 'silk_profile' is not defined #172

coderbhupendra opened this issue Mar 19, 2017 · 5 comments

Comments

@coderbhupendra
Copy link

do I need to add some extra code for adding @silk_profile

@avelis
Copy link
Collaborator

avelis commented Mar 23, 2017

@coderbhupendra Can you provide a stacktrace outlining you error? At best, right now, I can suggest to make sure silk is added to the list of installed apps in your Django settings file.

@coderbhupendra
Copy link
Author

coderbhupendra commented Mar 23, 2017

my setting.py

SILKY_PYTHON_PROFILER = True
..

INSTALLED_APPS = [
	..
	'silk',
	]
MIDDLEWARE = [..
	'silk.middleware.SilkyMiddleware',
	]

Here is how am using @silk_profile in views.py

class ItemSearchViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
	serializer_class = ItemSearchSerializer  
	permission_classes = (permissions.IsAuthenticatedOrReadOnly,) 

	@silk_profile(name='get_queryset')
	def get_queryset(self):
			request = self.request
			queryset = EmptySearchQuerySet()

			if request.GET.get('q', ''):
				query = request.GET.get('q', '')
			return queryset

On running my code it give following error:

Unhandled exception in thread started by <function wrapper at 0x7f5a09aa4938>
Traceback (most recent call last):
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
    self.check(display_num_errors=True)
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 374, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 361, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 24, in check_resolver
    for pattern in resolver.url_patterns:
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 313, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/berry/api/env/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 306, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/berry/api/products/products/urls.py", line 18, in <module>
    from items import views
  File "/home/berry/api/products/items/views.py", line 101, in <module>
    class ItemSearchViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
  File "/home/berry/api/products/items/views.py", line 105, in ItemSearchViewSet
    @silk_profile(name='get_queryset')

@avelis
Copy link
Collaborator

avelis commented Mar 25, 2017

@coderbhupendra In this scenario, is the decorator imported at the top of the view file as so:

from silk.profiling.profiler import silk_profile

I am sure you do but wanted to make sure I covered that assumption.

@coderbhupendra
Copy link
Author

@avelis I wasnt importing this . bsc i didnt knew how to import it , thanks it workd now

@avelis avelis closed this as completed Mar 27, 2017
avelis added a commit that referenced this issue Jun 12, 2017
Addresses #172 & #180

Adds import line to help others know where the location of the silk profiler exists within the library.
avelis added a commit that referenced this issue Jun 12, 2017
Helps #172 & #180

Adds import line with the location of the silk_profile decorator.
@davidhalter
Copy link

BTW: I also think the documentation and README are very unclear on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants