#36171: When saving an object(null=True, blank=True) with an empty string 
__str__
in the admin page.
----------------------------+-----------------------------------------
     Reporter:  Antoliny    |                     Type:  Bug
       Status:  new         |                Component:  contrib.admin
      Version:  5.1         |                 Severity:  Normal
     Keywords:  blank, str  |             Triage Stage:  Unreviewed
    Has patch:  0           |      Needs documentation:  0
  Needs tests:  0           |  Patch needs improvement:  0
Easy pickings:  0           |                    UI/UX:  0
----------------------------+-----------------------------------------
 When a field that allows blank and null is used as `__str__`, an issue
 occurs when saving the object in the admin page if the value is empty.

 **TestCase**

 {{{
 class Comment(models.Model):
     author = models.CharField(max_length=128, null=True, blank=True)
     content = models.CharField(max_length=128)

     def __str__(self):
         return self.author
 }}}
 [[Image(save_error.png)]]
 When clicking the save-related button, the following error is returned.
 [[Image(error.png)]]
 Everytime an object is saved in the admin page, a `LogEntry` is also
 created. It seems that an issue occurs when `LogEntry` tries to use the
 object's `__str__`.

 My guess is that the `to_python` method in the `CharField(Form)` performs
 a `strip()` process, causing the value entered in the admin page to be ''
 "instead of "". As a result, it is treated as `None`, and an issue occurs
 when `LogEntry` tries to use `__str__` on that value.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36171>
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/01070194d4341ce6-e07f0d47-aec8-4afe-854d-68dc36dcd2c7-000000%40eu-central-1.amazonses.com.

Reply via email to