mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #28974 -- Made refresh_from_db() hint routers about its instance.
This commit is contained in:
parent
0f5a741ada
commit
f5a989e603
2 changed files with 11 additions and 2 deletions
|
@ -2,6 +2,7 @@ import datetime
|
|||
import pickle
|
||||
from io import StringIO
|
||||
from operator import attrgetter
|
||||
from unittest.mock import Mock
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
@ -103,6 +104,14 @@ class QueryTestCase(TestCase):
|
|||
self.assertEqual(dive.title, "Dive into Python (on default)")
|
||||
self.assertEqual(dive._state.db, "default")
|
||||
|
||||
def test_refresh_router_instance_hint(self):
|
||||
router = Mock()
|
||||
router.db_for_read.return_value = None
|
||||
book = Book.objects.create(title='Dive Into Python', published=datetime.date(1957, 10, 12))
|
||||
with self.settings(DATABASE_ROUTERS=[router]):
|
||||
book.refresh_from_db()
|
||||
router.db_for_read.assert_called_once_with(Book, instance=book)
|
||||
|
||||
def test_basic_queries(self):
|
||||
"Queries are constrained to a single database"
|
||||
dive = Book.objects.using('other').create(title="Dive into Python", published=datetime.date(2009, 5, 4))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue