Projet

Général

Profil

0001-csv_import-ignore-uncommitted-users-when-checking-un.patch

Benjamin Dauvergne, 14 juillet 2020 18:24

Télécharger (1,62 ko)

Voir les différences:

Subject: [PATCH 1/4] csv_import: ignore uncommitted users when checking
 uniqueness (#44805)

 src/authentic2/csv_import.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/authentic2/csv_import.py
25 25
from django import forms
26 26
from django.core.exceptions import FieldDoesNotExist
27 27
from django.core.validators import RegexValidator
28
from django.db import IntegrityError
28
from django.db import IntegrityError, models
29 29
from django.db.transaction import atomic
30 30
from django.utils import six
31 31
from django.utils.encoding import force_bytes
......
370 370
        self.ou = ou or get_default_ou()
371 371
        self.errors = []
372 372
        self.csv_importer = CsvImporter()
373
        self.max_user_id = User.objects.aggregate(max=models.Max('id'))['max'] or -1
373 374

  
374 375
        def parse_csv():
375 376
            if not self.csv_importer.run(fd_or_str, encoding):
......
564 565

  
565 566
    def check_unique_constraints(self, row, unique_map, user=None):
566 567
        ou_users = User.objects.filter(ou=self.ou)
567
        users = User.objects.all()
568
        # ignore new users
569
        users = User.objects.exclude(id__gt=self.max_user_id)
568 570
        if user:
569 571
            users = users.exclude(pk=user.pk)
570 572
            ou_users = ou_users.exclude(pk=user.pk)
571
-