mirror of
https://github.com/django/django.git
synced 2025-10-10 07:19:11 +00:00
Refs #27222 -- Deduplicated db_returning fields in Model.save().
Follow-up to 94680437a45a71c70ca8bd2e68b72aa1e2eff337.
This commit is contained in:
parent
8c621e9642
commit
e059bbec96
@ -1153,7 +1153,8 @@ class Model(AltersData, metaclass=ModelBase):
|
||||
getattr(self, field.attname) if raw else field.pre_save(self, False)
|
||||
)
|
||||
if hasattr(value, "resolve_expression"):
|
||||
returning_fields.append(field)
|
||||
if field not in returning_fields:
|
||||
returning_fields.append(field)
|
||||
elif field.db_returning:
|
||||
returning_fields.remove(field)
|
||||
results = self._do_insert(
|
||||
|
@ -42,6 +42,16 @@ class ReturningValuesTests(TestCase):
|
||||
),
|
||||
captured_queries[-1]["sql"],
|
||||
)
|
||||
self.assertEqual(
|
||||
captured_queries[-1]["sql"]
|
||||
.split("RETURNING ")[1]
|
||||
.count(
|
||||
connection.ops.quote_name(
|
||||
ReturningModel._meta.get_field("created").column
|
||||
),
|
||||
),
|
||||
1,
|
||||
)
|
||||
self.assertTrue(obj.pk)
|
||||
self.assertIsInstance(obj.created, datetime.datetime)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user