#37147: Empty form for inlines breaks when using db_default on primary key field
-------------------------------------+-------------------------------------
               Reporter:  Mariusz    |          Owner:  Mariusz Felisiak
  Felisiak                           |
                   Type:  Bug        |         Status:  assigned
              Component:  Forms      |        Version:  6.0
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Using `db_default` with the new `UUID4` or `UUID7` functions breaks saving
 inlines. For example,

 - `models.py`
 {{{#!python
 class MyMain(models.Model):
     uuid = models.UUIDField(primary_key=True, db_default=UUID7(),
 editable=False, verbose_name="UUID")
     name = models.CharField(max_length=100)

 class MyChild(models.Model):
     name = models.CharField(max_length=100)
     parent = models.ForeignKey(MyMain, models.DB_CASCADE)
 }}}

 - `admin.py`

 {{{#!python
 class ChildAdmin(admin.TabularInline):
     model = MyChild
     extra = 0


 class MainAdmin(admin.ModelAdmin):
     inlines = [ChildAdmin]


 admin.site.register(MyChild)
 admin.site.register(MyMain, MainAdmin)
 }}}

 `DatabaseDefault` instances are rendered as values of the parent fields:

 {{{
 <tr class="form-row  empty-form" id="mychild_set-empty">
   <td class="original">
      <input type="hidden" name="mychild_set-__prefix__-id" id
 ="id_mychild_set-__prefix__-id">
      <input type="hidden" name="mychild_set-__prefix__-parent"
 value="&lt;django.db.models.expressions.DatabaseDefault object at
 0x750a2aa14ad0&gt;" id="id_mychild_set-__prefix__-parent">
   </td>
   ...
 }}}
 which causes the following error when trying to save:
 {{{
 [{'parent': ['The inline value did not match the parent instance.']}]
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37147>
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/0107019ea1ba870c-202faaac-294b-4361-a632-e141a3448882-000000%40eu-central-1.amazonses.com.

Reply via email to