#37139: InlineAdmin breaks when using db_default on primary key field without a
python default
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):
I get that `db_default` is one of the main use cases for these new
functions. But I presume we already had this problem with `RandomUUID` in
`contrib.postgres`. The "new feature" here IMO is just the cross-database
abstraction to replace `RandomUUID`. (I'm motivated to get the fix in
before 6.1 beta, so the difference doesn't amount to much.)
----
I can get the add page to load when applying this tweak:
{{{#!diff
diff --git a/django/db/models/base.py b/django/db/models/base.py
index d53da600d7..21b9c80687 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -709,9 +709,10 @@ class Model(AltersData, metaclass=ModelBase):
def _is_pk_set(self, meta=None):
pk_val = self._get_pk_val(meta)
+ is_set = lambda val: val is None or isinstance(val,
DatabaseDefault)
return not (
- pk_val is None
- or (isinstance(pk_val, tuple) and any(f is None for f in
pk_val))
+ is_set(pk_val)
+ or (isinstance(pk_val, tuple) and any(is_set(f) for f in
pk_val))
)
def get_deferred_fields(self):
}}}
Obviously we'll need to check the other uses.
--
Ticket URL: <https://code.djangoproject.com/ticket/37139#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019e8dc3356d-c3ba7cbe-0472-41aa-9d24-99da9a8f58d8-000000%40eu-central-1.amazonses.com.