[Django] #19918: select_for_update runs on db_for_read rather than db_for_write

26 views
Skip to first unread message

Django

unread,
Feb 26, 2013, 4:46:28 AM2/26/13
to django-...@googlegroups.com
#19918: select_for_update runs on db_for_read rather than db_for_write
----------------------------------------------+--------------------
Reporter: alexandruioan.cucu@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Discussion on the developer group:
https://groups.google.com/forum/?fromgroups=#!topic/django-
developers/38gWxf5qfxg

This bug is quite easy to reproduce if you use mysql with a master-slave
replication setup and start the slave db with a --read-only flag:

{{{
Traceback:
File "/home/kux/workspace/src/other/django/django/core/handlers/base.py"
in get_response
111. response = callback(request,
*callback_args, **callback_kwargs)
File
"/home/kux/workspace/src/other/django/django/contrib/admin/options.py" in
wrapper
366. return self.admin_site.admin_view(view)(*args,
**kwargs)
File "/home/kux/workspace/src/other/django/django/utils/decorators.py" in
_wrapped_view
91. response = view_func(request, *args, **kwargs)
File
"/home/kux/workspace/src/other/django/django/views/decorators/cache.py" in
_wrapped_view_func
89. response = view_func(request, *args, **kwargs)
File "/home/kux/workspace/src/other/django/django/contrib/admin/sites.py"
in inner
196. return view(request, *args, **kwargs)
File "/home/kux/workspace/src/other/django/django/db/transaction.py" in
inner
209. return func(*args, **kwargs)
File "/home/kux/workspace/src/other/django-cms/cms/admin/pageadmin.py" in
wrap
154. Page.objects.select_for_update()
File "/home/kux/workspace/src/other/django/django/db/models/query.py" in
exists
562. return self.query.has_results(using=self.db)
File "/home/kux/workspace/src/other/django/django/db/models/sql/query.py"
in has_results
441. return bool(compiler.execute_sql(SINGLE))
File
"/home/kux/workspace/src/other/django/django/db/models/sql/compiler.py" in
execute_sql
818. cursor.execute(sql, params)
File "/home/kux/workspace/src/other/django/django/db/backends/util.py" in
execute
40. return self.cursor.execute(sql, params)
File
"/home/kux/workspace/src/other/django/django/db/backends/mysql/base.py" in
execute
114. return self.cursor.execute(query, args)
File "/home/kux/workspace/envs/hb23/local/lib/python2.7/site-
packages/MySQLdb/cursors.py" in execute
174. self.errorhandler(self, exc, value)
File "/home/kux/workspace/envs/hb23/local/lib/python2.7/site-
packages/MySQLdb/connections.py" in defaulterrorhandler
36. raise errorclass, errorvalue

Exception Type: DatabaseError at /admin/cms/page/add/
Exception Value: (1290, 'The MySQL server is running with the --read-only
option so it cannot execute this statement')
}}}

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

Django

unread,
Feb 26, 2013, 4:50:26 AM2/26/13
to django-...@googlegroups.com
#19918: select_for_update runs on db_for_read rather than db_for_write
-------------------------------------+-------------------------------------
Reporter: | Owner: kux
alexandruioan.cucu@… | Status: assigned
Type: Bug | Version: master
Component: Database layer | Resolution:
(models, ORM) | Triage Stage:
Severity: Normal | Unreviewed
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by kux):

* owner: nobody => kux
* needs_docs: => 0
* status: new => assigned
* needs_tests: => 0
* needs_better_patch: => 0


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

Django

unread,
Feb 26, 2013, 4:58:50 AM2/26/13
to django-...@googlegroups.com
#19918: select_for_update runs on db_for_read rather than db_for_write
-------------------------------------+-------------------------------------
Reporter: | Owner: kux
alexandruioan.cucu@… | Status: assigned
Type: Bug | Version: master
Component: Database layer | Resolution:
(models, ORM) | Triage Stage:
Severity: Normal | Unreviewed
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by kux):

For patch see pull request: https://github.com/django/django/pull/852

--
Ticket URL: <https://code.djangoproject.com/ticket/19918#comment:2>

Django

unread,
Feb 26, 2013, 5:54:49 AM2/26/13
to django-...@googlegroups.com
#19918: select_for_update runs on db_for_read rather than db_for_write
-------------------------------------+-------------------------------------
Reporter: | Owner: kux
alexandruioan.cucu@… | Status: assigned
Type: Bug | Version: master
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by akaariai):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/19918#comment:3>

Django

unread,
Apr 11, 2013, 4:40:19 AM4/11/13
to django-...@googlegroups.com
#19918: select_for_update runs on db_for_read rather than db_for_write
-------------------------------------+-------------------------------------
Reporter: | Owner: kux
alexandruioan.cucu@… | Status: assigned
Type: Bug | Version: master
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Ready for
Severity: Normal | checkin

Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by kux):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/19918#comment:4>

Django

unread,
Apr 11, 2013, 7:28:36 AM4/11/13
to django-...@googlegroups.com
#19918: select_for_update runs on db_for_read rather than db_for_write
-------------------------------------+-------------------------------------
Reporter: | Owner: kux
alexandruioan.cucu@… | Status: assigned
Type: Bug | Version: master
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by claudep):

* stage: Ready for checkin => Accepted


Comment:

Sorry, but the "Ready for checkin" flag should be set by another reviewer,
not by the patch author.

--
Ticket URL: <https://code.djangoproject.com/ticket/19918#comment:5>

Django

unread,
May 2, 2013, 1:03:59 PM5/2/13
to django-...@googlegroups.com
#19918: select_for_update runs on db_for_read rather than db_for_write
-------------------------------------+-------------------------------------
Reporter: | Owner: kux
alexandruioan.cucu@… | Status: assigned
Type: Bug | Version: master
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by anonymous coward):

Nifty. I'm glad to see a patch for this. I was having the same issue, and
decided to search for an existing ticket before adding excessive bytes to
the Interwebz.

--
Ticket URL: <https://code.djangoproject.com/ticket/19918#comment:6>

Django

unread,
May 23, 2013, 3:45:27 PM5/23/13
to django-...@googlegroups.com
#19918: select_for_update runs on db_for_read rather than db_for_write
-------------------------------------+-------------------------------------
Reporter: | Owner: kux
alexandruioan.cucu@… | Status: assigned
Type: Bug | Version: master
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

The fact that the db was running with --read-only flag is a fortunate
case. Otherwise this bug would cause subtle concurrency issues since all
exclusive locks would be held on the slave db instead of master.

--
Ticket URL: <https://code.djangoproject.com/ticket/19918#comment:7>

Django

unread,
Aug 6, 2013, 9:53:14 AM8/6/13
to django-...@googlegroups.com
#19918: select_for_update runs on db_for_read rather than db_for_write
-------------------------------------+-------------------------------------
Reporter: | Owner: kux
alexandruioan.cucu@… | Status: closed
Type: Bug | Version: master
Component: Database layer | Resolution: fixed

(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"1c64a0f29e47a3da1dfac06b04ef84280bd809a7"]:
{{{
#!CommitTicketReference repository=""
revision="1c64a0f29e47a3da1dfac06b04ef84280bd809a7"
Fixed #19918 -- Modified select_for_update to run on the write database.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19918#comment:8>

Django

unread,
Aug 6, 2013, 10:58:47 AM8/6/13
to django-...@googlegroups.com
#19918: select_for_update runs on db_for_read rather than db_for_write
-------------------------------------+-------------------------------------
Reporter: | Owner: kux
alexandruioan.cucu@… | Status: closed
Type: Bug | Version: master
Component: Database layer | Resolution: fixed
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"80b95a2b1fc8c8425a81a23706af971061dc238f"]:
{{{
#!CommitTicketReference repository=""
revision="80b95a2b1fc8c8425a81a23706af971061dc238f"
[1.6.x] Fixed #19918 -- Modified select_for_update to run on the write
database.

Backport of 1c64a0f29e from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19918#comment:9>

Reply all
Reply to author
Forward
0 new messages