Opened 3 hours ago
Last modified 3 hours ago
#36171 assigned Bug
When saving an object(null=True, blank=True) with an empty string __str__ in the admin page.
Reported by: | Antoliny | Owned by: | Antoliny |
---|---|---|---|
Component: | contrib.admin | Version: | 5.1 |
Severity: | Normal | Keywords: | blank, str |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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
When clicking the save-related button, the following error is returned.
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.
Attachments (3)
Change History (6)
by , 3 hours ago
Attachment: | save_error.png added |
---|
by , 3 hours ago
comment:1 by , 3 hours ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:2 by , 3 hours ago
Description: | modified (diff) |
---|
by , 3 hours ago
Attachment: | save_error_resize.png added |
---|
comment:3 by , 3 hours ago
Description: | modified (diff) |
---|