Project

General

Profile

Actions

Bug #102150

open

AttributeError: booking has multiple checks

Added by Sentry Io 12 months ago. Updated 4 days ago.

Status:
Solution proposée
Priority:
Normal
Category:
-
Target version:
-
Start date:
13 February 2025
Due date:
% Done:

0%

Estimated time:
Patch proposed:
No
Planning:
No

Description

https://sentry.entrouvert.org/entrouvert/publik/issues/137994/

AttributeError: booking has multiple checks
(8 additional frame(s) were not displayed)
...
  File "chrono/manager/views.py", line 3615, in get_context_data
    self.complete_event_attributes(self.agenda, event, context)
  File "chrono/manager/views.py", line 3601, in complete_event_attributes
    event.present_count = len([b for b in booked if b.user_check and b.user_check.presence])
  File "chrono/manager/views.py", line 3601, in <listcomp>
    event.present_count = len([b for b in booked if b.user_check and b.user_check.presence])
  File "django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "chrono/agendas/models.py", line 3470, in user_check
    raise AttributeError('booking has multiple checks')

Related issues 2 (0 open2 closed)

Related to Chrono - Développement #80371: plages libres, permettre plusieurs pointages par réservationFerméValentin Deniaud10 August 2023

Actions
Has duplicate Chrono - Bug #94909: agendas: ne pas planter s'il y a plusieurs pointages pour une réservationRejeté05 September 2024

Actions
Actions #2

Updated by Robot Gitea 11 months ago

  • Status changed from Nouveau to En cours

Lauréline Guérin (lguerin) a ouvert une pull request sur Gitea concernant cette demande :

Actions #3

Updated by Robot Gitea 11 months ago

  • Status changed from En cours to Solution proposée
Actions #4

Updated by Robot Gitea 11 months ago

  • Status changed from Solution proposée to Solution validée

Gael Pasgrimaud (gpasgrimaud) a approuvé une pull request sur Gitea concernant cette demande :

Actions #5

Updated by Benjamin Dauvergne 11 months ago

  • Status changed from Solution validée to En cours

Le patch ne corrige pas le problème, sans un index d'unicité ou une transaction avec un lock sur le kwargs de get_or_create() ce n'est pas possible1 de garantir l'atomicité et d'éviter un MultipleObjectsReturned. L'index d'unicité donne un verrou implicite entre appels à get_or_create().

Je ne sais pas si on souhaite une unicité globale sur (event, user_external_id). Si ce n'est pas le cas il faudrait un verrou dans une transaction sur event via select_for_update() (c'est pas le verrou le plus fin mais ça parait suffisant), ça ne protégera que cette section critique, si d'autres endroits crée des Booking sur cet Event il faudrait le même verrou.

with atomic():
    list(Event.objects.filter(id=event.id).select_for_update())
    cur.execute('SELECT pg_advisory_lock(%s)', [lock_id])
    ...etc event.booking_set.get_or_create(user_external_id=user_external_id, ...)

1 voir le warning dans https://docs.djangoproject.com/en/5.1/ref/models/querysets/#get-or-create

Actions #6

Updated by Gael Pasgrimaud 11 months ago

  • Project changed from 369 to Chrono
Actions #7

Updated by Lauréline Guérin (absente) 11 months ago

  • Private changed from Yes to No
Actions #8

Updated by Benjamin Dauvergne 11 months ago

Autre solution un index unique partiel en ajoutant un champ booléen unique_by_user_external_id = BooleanField(default=False) et un index partiel sur (event_id, user_external_id) WHERE unique_by_user_external_id et ajouter unique_by_user_external_id=True dans get_or_create().

Actions #9

Updated by Robot Gitea 11 months ago

Lauréline Guérin (lguerin) a fermé une pull request sur Gitea concernant cette demande.

Actions #10

Updated by Lauréline Guérin (absente) 11 months ago

  • Status changed from En cours to Nouveau
  • Assignee deleted (Lauréline Guérin (absente))
Actions #11

Updated by Valentin Deniaud 11 months ago

  • Has duplicate Bug #94909: agendas: ne pas planter s'il y a plusieurs pointages pour une réservation added
Actions #12

Updated by Valentin Deniaud 11 months ago

Actions #13

Updated by Valentin Deniaud 5 days ago

  • Assignee set to Valentin Deniaud
Actions #15

Updated by Valentin Deniaud 4 days ago

  • Status changed from Nouveau to En cours

🤖 Une pull request concernant ce ticket a été ouverte :

Actions #16

Updated by Valentin Deniaud 4 days ago

  • Status changed from En cours to Solution proposée
Actions

Also available in: Atom PDF