concurency issue
There is almost no chance that scenario described below will happen in production. It requires two users editing significantly start date of two different visits for the same user at the same time.
Nevertheless, it can happen in unit tests, which might be difficult to debug:
visit1 = create_visit(self.study_subject)
visit2 = create_visit(self.study_subject)
visit1.datetime_end = get_today_midnight_date() + datetime.timedelta(days=1)
visit2.datetime_end = get_today_midnight_date() + datetime.timedelta(days=2)
visit1.save()
visit2.save()
This code is supposed to create two visits with different start dates. So the result should be as follows:
- visit.visit_number=1
- visit.visit_number=2
However, due to concurrency of save and signal on post save we get:
- visit.visit_number=2
- visit.visit_number=2