Skip to content

Commit

Permalink
Fixed #19918 -- Modified select_for_update to run on the write database.
Browse files Browse the repository at this point in the history
  • Loading branch information
kux authored and timgraham committed Aug 6, 2013
1 parent 1280675 commit 1c64a0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions django/db/models/query.py
Expand Up @@ -742,6 +742,7 @@ def select_for_update(self, **kwargs):
# Default to false for nowait
nowait = kwargs.pop('nowait', False)
obj = self._clone()
obj._for_write = True
obj.query.select_for_update = True
obj.query.select_for_update_nowait = nowait
return obj
Expand Down
14 changes: 13 additions & 1 deletion tests/select_for_update/tests.py
Expand Up @@ -5,11 +5,13 @@
import unittest

from django.conf import settings
from django.db import transaction, connection
from django.db import transaction, connection, router
from django.db.utils import ConnectionHandler, DEFAULT_DB_ALIAS, DatabaseError
from django.test import (TransactionTestCase, skipIfDBFeature,
skipUnlessDBFeature)

from multiple_database.tests import TestRouter

from .models import Person

# Some tests require threading, which might not be available. So create a
Expand Down Expand Up @@ -254,3 +256,13 @@ def test_transaction_dirty_managed(self):
"""
people = list(Person.objects.select_for_update())
self.assertTrue(transaction.is_dirty())

@skipUnlessDBFeature('has_select_for_update')
def test_select_for_update_on_multidb(self):
old_routers = router.routers
try:
router.routers = [TestRouter()]
query = Person.objects.select_for_update()
self.assertEqual(router.db_for_write(Person), query.db)
finally:
router.routers = old_routers

0 comments on commit 1c64a0f

Please sign in to comment.