mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #27222 -- Refreshed model field values assigned expressions on save().
Removed the can_return_columns_from_insert skip gates on existing field_defaults tests to confirm the expected number of queries are performed and that returning field overrides are respected.
This commit is contained in:
committed by
Mariusz Felisiak
parent
55a0073b3b
commit
94680437a4
@@ -1,5 +1,6 @@
|
||||
import inspect
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
from unittest import mock
|
||||
|
||||
@@ -12,6 +13,7 @@ from django.db import (
|
||||
models,
|
||||
transaction,
|
||||
)
|
||||
from django.db.models.functions import Now
|
||||
from django.db.models.manager import BaseManager
|
||||
from django.db.models.query import MAX_GET_RESULTS, EmptyQuerySet
|
||||
from django.test import (
|
||||
@@ -558,6 +560,26 @@ class ModelTest(TestCase):
|
||||
with self.subTest(case=case):
|
||||
self.assertIs(case._is_pk_set(), True)
|
||||
|
||||
def test_save_expressions(self):
|
||||
article = Article(pub_date=Now())
|
||||
article.save()
|
||||
expected_num_queries = (
|
||||
0 if connection.features.can_return_columns_from_insert else 1
|
||||
)
|
||||
with self.assertNumQueries(expected_num_queries):
|
||||
article_pub_date = article.pub_date
|
||||
self.assertIsInstance(article_pub_date, datetime)
|
||||
# Sleep slightly to ensure a different database level NOW().
|
||||
time.sleep(0.1)
|
||||
article.pub_date = Now()
|
||||
article.save()
|
||||
expected_num_queries = (
|
||||
0 if connection.features.can_return_rows_from_update else 1
|
||||
)
|
||||
with self.assertNumQueries(expected_num_queries):
|
||||
self.assertIsInstance(article.pub_date, datetime)
|
||||
self.assertGreater(article.pub_date, article_pub_date)
|
||||
|
||||
|
||||
class ModelLookupTest(TestCase):
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user