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

No objects in cache #755

Open
jachym opened this issue May 13, 2019 · 6 comments

Comments

Projects
None yet
2 participants
@jachym
Copy link
Contributor

commented May 13, 2019

Describe the bug
After login, django-helpdesk shows following error dialog:

obrazek

When checking where the bug comes from, I came to

helpdesk/views/staff.py

line 1015

        model_object = query_tickets_by_args(cache.get('ticket_qs'), '-date_created', **request.query_params)

Where cache.get('ticket_qs') returns empty value and so helpdesk/lib.py at line 273 in query_tickets_by_args

queryset = objects.all().order_by(order_by)

Raises AttributeError, since NoneType objects does not have all method

After refresh, everything works fine, till next browser restart - so it's hard to debug.

My question is: cache from staff.py is supposed to be django.core.cache and this should contain ticket_qs - should it always contain?

To Reproduce

  1. Go to helpdesk app
  2. Click on login
  3. Scroll down to login
  4. See error
  5. Follow the javascript-debugging console to see the error request, which is

/helpdesk/datatables_ticket_list/?draw=1&columns[0][data]=id&columns[0][name]=&columns[0][searchable]=true&columns[0][orderable]=false&columns[0][search][value]=&columns[0][search][regex]=false&columns[1][data]=ticket&columns[1][name]=&columns[1][searchable]=true&columns[1][orderable]=true&columns[1][search][value]=&columns[1][search][regex]=false&columns[2][data]=priority&columns[2][name]=&columns[2][searchable]=true&columns[2][orderable]=true&columns[2][search][value]=&columns[2][search][regex]=false&columns[3][data]=queue&columns[3][name]=&columns[3][searchable]=true&columns[3][orderable]=true&columns[3][search][value]=&columns[3][search][regex]=false&columns[4][data]=status&columns[4][name]=&columns[4][searchable]=true&columns[4][orderable]=true&columns[4][search][value]=&columns[4][search][regex]=false&columns[5][data]=created&columns[5][name]=&columns[5][searchable]=true&columns[5][orderable]=true&columns[5][search][value]=&columns[5][search][regex]=false&columns[6][data]=due_date&columns[6][name]=&columns[6][searchable]=true&columns[6][orderable]=true&columns[6][search][value]=&columns[6][search][regex]=false&columns[7][data]=assigned_to&columns[7][name]=&columns[7][searchable]=true&columns[7][orderable]=true&columns[7][search][value]=&columns[7][search][regex]=false&columns[8][data]=time_spent&columns[8][name]=&columns[8][searchable]=true&columns[8][orderable]=true&columns[8][search][value]=&columns[8][search][regex]=false&order[0][column]=0&order[0][dir]=asc&start=0&length=25&search[value]=&search[regex]=false&_=1557782308894

Expected behavior
The url returns correct data

Desktop (please complete the following information):

  • OS: linux
  • Chrome and Firefox current versions

It seems, that following patch does the job, but I'm not sure, this is clean solution:

diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py
index 8e956de..43d1a78 100644
--- a/helpdesk/views/staff.py
+++ b/helpdesk/views/staff.py
@@ -1012,7 +1012,10 @@ def datatables_ticket_list(request):
     serializers.py. The serializers and this view use django-rest_framework methods
     """
     try:
-        model_object = query_tickets_by_args(cache.get('ticket_qs'), '-date_created', **request.query_params)
+        objects = cache.get('ticket_qs')
+        if not objects:
+             objects = Ticket.objects
+        model_object = query_tickets_by_args(objects, '-date_created', **request.query_params)
         serializer = TicketSerializer(model_object['items'], many=True)
         result = dict()
         result['data'] = serializer.data

@jachym jachym added the bug label May 13, 2019

@gwasser

This comment has been minimized.

Copy link
Member

commented May 14, 2019

Thanks for the report! Just to check, is this in the most recent 0.2.x release, or are you looking at develop?

@gwasser gwasser added this to the 0.2.16 milestone May 14, 2019

@jachym

This comment has been minimized.

Copy link
Contributor Author

commented May 14, 2019

Yes, this is on the develop branch

@gwasser gwasser modified the milestones: 0.2.16, 0.3.0 May 14, 2019

@jachym

This comment has been minimized.

Copy link
Contributor Author

commented May 21, 2019

This does not seem to be the right solution :-(

@jachym

This comment has been minimized.

Copy link
Contributor Author

commented May 21, 2019

It seems that setting Cache as described in https://docs.djangoproject.com/en/2.2/topics/cache/ and setting HELPDESK_USE_SERVERSIDE_PROCESSING = True solved the probelm (?)

@gwasser

This comment has been minimized.

Copy link
Member

commented May 22, 2019

Are you using the Database cache? I think that would be easy to integrate since we already expect a SQL database anyway. Let me know what you think and what your testing reveals! Thanks.

@jachym

This comment has been minimized.

Copy link
Contributor Author

commented May 22, 2019

I set the database cache and since then I did not face any of such problem.

I would suggest to add some information about necessity of setting the cache in the docs. Reference to official django documentation should be enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.