#34072 closed Bug (invalid)

django += 1 increments by 2 instead of 1

Reported by: kaushik kothiya Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords: ASGI, Channel, ORM, F Expiration, Race Condition
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

from django.db.models import F
from hotel.models import Hotel

Hotel.objects.filter(city='Chicago').update(total_like=F('total_like'+1))

total_like += 1 increments by 2 instead of 1
So here is my question: What kind of locking mechanisms are available to Django, to deal with situations similar to this?

After installing the channel and HTTPS request also send wia asgi. but if the same code is in use WSGI request then working fine.

https://stackoverflow.com/questions/68778007/django-1-increments-by-2-instead-of-1
https://stackoverflow.com/questions/1030270/race-conditions-in-django

Attachments (2)

Screenshot_8.png (45.9 KB ) - added by kaushik kothiya 19 months ago.
Code photo
Screenshot_9.png (141.7 KB ) - added by kaushik kothiya 19 months ago.
ASGI File

Download all attachments as: .zip

Change History (3)

by kaushik kothiya, 19 months ago

Attachment: Screenshot_8.png added

Code photo

by kaushik kothiya, 19 months ago

Attachment: Screenshot_9.png added

ASGI File

comment:1 by Mariusz Felisiak, 19 months ago

Resolution: invalid
Status: newclosed

Thanks for this ticket, however Trac is not a support channel and it's a support question. You can use select_for_update() to protect yourself against the race conditions (it's already mentioned in Stack Overflow's answers). Closing per TicketClosingReasons/UseSupportChannels.

Note: See TracTickets for help on using tickets.
Back to Top