[Django] #34072: django += 1 increments by 2 instead of 1

2 views
Skip to first unread message

Django

unread,
Oct 6, 2022, 4:24:24 AM10/6/22
to django-...@googlegroups.com
#34072: django += 1 increments by 2 instead of 1
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
kaushikk25 |
Type: Bug | Status: new
Component: Database | Version: 3.2
layer (models, ORM) | Keywords: ASGI, Channel, ORM,
Severity: Normal | F Expiration, Race Condition
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/34072>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 6, 2022, 4:26:01 AM10/6/22
to django-...@googlegroups.com
#34072: django += 1 increments by 2 instead of 1
-------------------------------------+-------------------------------------
Reporter: kaushikk25 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ASGI, Channel, ORM, | Triage Stage:
F Expiration, Race Condition | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kaushikk25):

* Attachment "Screenshot_8.png" added.

Code photo

Django

unread,
Oct 6, 2022, 4:26:53 AM10/6/22
to django-...@googlegroups.com
#34072: django += 1 increments by 2 instead of 1
-------------------------------------+-------------------------------------
Reporter: kaushik kothiya | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ASGI, Channel, ORM, | Triage Stage:
F Expiration, Race Condition | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kaushik kothiya):

* Attachment "Screenshot_9.png" added.

ASGI File

Django

unread,
Oct 6, 2022, 5:01:34 AM10/6/22
to django-...@googlegroups.com
#34072: django += 1 increments by 2 instead of 1
-------------------------------------+-------------------------------------
Reporter: kaushik kothiya | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: ASGI, Channel, ORM, | Triage Stage:
F Expiration, Race Condition | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/34072#comment:1>

Reply all
Reply to author
Forward
0 new messages