Project

General

Profile

0001-mdph13-move-transaction.atomic-inside-create_or_upda.patch

Benjamin Dauvergne, 13 Mar 2019 11:11 PM

Download (2.43 KB)

View differences:

Subject: [PATCH] mdph13: move transaction.atomic() inside create_or_update()
 (#31401)

 passerelle/contrib/mdph13/models.py | 37 ++++++++++++++---------------
 1 file changed, 18 insertions(+), 19 deletions(-)
passerelle/contrib/mdph13/models.py
213 213
        email = email.strip()
214 214
        if not self.EMAIL_RE.match(email):
215 215
            raise APIError('email is not valid', http_status=400)
216
        with transaction.atomic():
217
            link, created, updated = Link.create_or_update(
218
                resource=self,
219
                NameID=NameID,
220
                file_number=file_number,
221
                secret=secret,
222
                dob=dob,
223
                email=email)
216
        link, created, updated = Link.create_or_update(
217
            resource=self,
218
            NameID=NameID,
219
            file_number=file_number,
220
            secret=secret,
221
            dob=dob,
222
            email=email)
224 223
        return {'link_id': link.pk, 'created': created, 'updated': updated}
225 224

  
226 225
    @endpoint(name='unlink',
......
351 350
            email=email)
352 351
        display_name = self._make_display_name(mdph_file)
353 352

  
354
        link, created = Link.objects.get_or_create(
355
            resource=resource,
356
            name_id=NameID,
357
            file_number=file_number,
358
            defaults={
359
                'secret': secret,
360
                'dob': dob,
361
                'display_name': display_name,
362
            })
353
        with transaction.atomic():
354
            link, created = Link.objects.get_or_create(
355
                resource=resource,
356
                name_id=NameID,
357
                file_number=file_number,
358
                defaults={
359
                    'secret': secret,
360
                    'dob': dob,
361
                    'display_name': display_name,
362
                })
363 363

  
364
        updated = False
365
        if not created:
364
            updated = False
366 365
            if link.secret != secret or link.dob != dob or link.display_name != display_name:
367 366
                link.secret = secret
368 367
                link.dob = dob
369
-