HassenPy / django-pdb

Gives you `manage.py runserver --pdb` and `manage.py test --pdb`
394 stars 61 forks source link

Fix for instance-based views #16

Closed ukch closed 9 years ago

ukch commented 11 years ago

When debugging instance-based views (such as those from django-haystack), a traceback is encountered:

Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  105.                         response = middleware_method(request, callback, callback_args, callback_kwargs)
File "/home/joel/src/django-pdb/django_pdb/middleware.py" in process_view
  55.         filename = inspect.getsourcefile(view_func)
File "/usr/lib/python2.7/inspect.py" in getsourcefile
  444.     filename = getfile(object)
File "/usr/lib/python2.7/inspect.py" in getfile
  420.                     'function, traceback, frame, or code object'.format(object))

Exception Type: TypeError at /discover/
Exception Value: <search.views.ProductSearchView object at 0x7fce1c84bfd0> is not a module, class, method, function, traceback, frame, or code object

To fix this error, inspect the class instead of the instance.

tomchristie commented 11 years ago

@ukch To confirm - are we talking about class-based-views or something else?

ukch commented 11 years ago

These are a form of class-based views, but different to the 'Django generic' ones. These are called using the __call__ method.

tomchristie commented 11 years ago

Not sure if supporting non-standard view setups is a good plan or not. I guess at the least we ought to verify that it doesn't break anything with eg how CBVs are currently handled.

ukch commented 11 years ago

A good point. I will check how this affects views that use the as_view method (the django.views.generic way of doing things).

ukch commented 11 years ago

@tomchristie I have ditched my previous attempt and have made a new fix using a try/except block instead.

jpulec commented 9 years ago

@ukch Just taking a look at this, if you're still interested in trying to get it work. It looks like it's still failing, since the instance of ProductSearchView doesn't have a __name__ attribute, which gets referenced on line 70 so we can print it later.

jpulec commented 9 years ago

Given how old this PR is, and that it currently doesn't work, I'm going to close it for now. Feel free to open another one.