django-silk icon indicating copy to clipboard operation
django-silk copied to clipboard

User interface fails without session middleware

Open claradaia opened this issue 5 years ago • 4 comments

Hello, guys. I am trying to integrate silk with my existing app which does not use the atuhentication or sessions middleware. Because of that, I get the following error when I try to access /silk:

...
   File "/usr/local/lib/python3.6/site-packages/silk/views/summary.py", line 78, in get
     c = self._create_context(request)
   File "/usr/local/lib/python3.6/site-packages/silk/views/summary.py", line 57, in _create_context
     raw_filters = request.session.get(self.filters_key, {})
 AttributeError: 'WSGIRequest' object has no attribute 'session'

Is there a workaround? I considered just copying the views and tweaking until it worked, but looking at the code I wonder if the sessions are essential for the proper function of the interface. If so, maybe add a warning about that to the docs?

claradaia avatar Jun 05 '19 21:06 claradaia

Hello!

  • As SessionMiddleware is used to persist the filters, could be a fix hide them on the UI if that is not present?

  • Regarding the AuthenticationMiddleware I think is more complicated because is used inside of user_passes_test; any possible solution? Or documentate that is required is enough?

If the changes are OK I would like to implement them!

Thank you!

mgaligniana avatar Dec 26 '22 15:12 mgaligniana

@SebCorbin sorry for the ping! But let me know if the ideas above makes sense for you, thank you!

mgaligniana avatar Jan 27 '23 16:01 mgaligniana

@mgaligniana I suggest

  • make the form agnostic from session if SessionMiddleware is not present (the test muse be hasattr(request, 'session')
  • as for AuthenticationMiddleware the SILKY_AUTHENTICATION should be enough to configure silk without auth but a simple access request.user in user_passes_test may raise an AttributeError so we may need to change that
  • add some tests with these left out in MIDDLEWARE setting using self.modify_settings or override_settings

SebCorbin avatar Jan 30 '23 08:01 SebCorbin

It has been half year but finally I added some progress! Sorry for the delay 🙏

I think I completed all your suggestions @SebCorbin! Let me know if they make sense for you and any change required.

Thank you!

mgaligniana avatar Jul 27 '23 21:07 mgaligniana