From 6e569566edc19c8e3400e2093cc2cd883df79655 Mon Sep 17 00:00:00 2001 From: detraz Date: Sun, 17 Mar 2019 17:20:11 +0100 Subject: [PATCH] Avoid lazy eval problems with django queryset --- users/models.py | 10 ++++++++++ users/views.py | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/users/models.py b/users/models.py index 2bb7decd..bc959a21 100755 --- a/users/models.py +++ b/users/models.py @@ -591,11 +591,21 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, @classmethod def mass_archive(cls, users_list): + """Mass Archive several users, take a queryset + Copy Queryset to avoid eval problem with queryset update""" + #Force eval of queryset + bool(users_list) + users_list = users_list.all() cls.mass_unassign_ips(users_list) users_list.update(state=User.STATE_ARCHIVE) @classmethod def mass_full_archive(cls, users_list): + """Mass Archive several users, take a queryset + Copy Queryset to avoid eval problem with queryset update""" + #Force eval of queryset + bool(users_list) + users_list = users_list.all() cls.mass_unassign_ips(users_list) cls.mass_delete_data(users_list) users_list.update(state=User.STATE_FULL_ARCHIVE) diff --git a/users/views.py b/users/views.py index 7c8149b5..ad8543b5 100644 --- a/users/views.py +++ b/users/views.py @@ -785,14 +785,13 @@ def mass_archive(request): to_archive_list = User.objects.exclude(id__in=all_has_access()).exclude(id__in=all_has_access(search_time=date)).exclude(state=User.STATE_NOT_YET_ACTIVE).exclude(state=User.STATE_FULL_ARCHIVE) if not full_archive: to_archive_list = to_archive_list.exclude(state=User.STATE_ARCHIVE) - number_to_archive = to_archive_list.count() if "valider" in request.POST: if full_archive: User.mass_full_archive(to_archive_list) else: User.mass_archive(to_archive_list) messages.success(request, _("%s users were archived.") % - number_to_archive + to_archive_list.count() ) return redirect(reverse('users:index')) to_archive_list = re2o_paginator(request, to_archive_list, pagination_number)