-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Fixed #27222 -- Refreshed model field values assigned expressions on save(). #19285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The unveiled failures are related to this ticket TL;DR the documented pattern for copying model instances breaks when some fields are deferred on the original instance. This poses a problem with this patch as it marks any field assigned a database expression at |
This is now based on #19445 |
django/db/models/base.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an explicit literal value is provided for a field there is no need to return it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except that I've written some code like this for MongodB where the id is ObjectIdAutoField
: Question.objects.create(id="000000000000000000000013")
. Previously, this would refresh id
to the returned value, ObjectId("000000000000000000000013")
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the same problem might happen with some form of UUID field that returns uuid.UUID
instances I guess. Could you write a regression test for it and file an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I imagine UUIDAutoField
(ticket-32577) could reproduce it. Do you have a more generic way in mind? I could try for some minimal implementation of UUIDFIeld
+ django.contrib.postgres.functions.RandomUUID
to create a regression test in postgres_tests
but this might be unnecessarily complicated in light of the MongoDB tests.
This works as a regression test, at least on SQLite and PostgreSQL. I'm unsure if all databases will accept it.
a = AutoModel.objects.create(pk="1")
self.assertEqual(a.pk, 1)
Trac ticket number
ticket-27222