[Django] #31047: Empty models.TextField being incorrectly saved as empty string

9 views
Skip to first unread message

Django

unread,
Nov 29, 2019, 12:39:23 PM11/29/19
to django-...@googlegroups.com
#31047: Empty models.TextField being incorrectly saved as empty string
-------------------------------------+-------------------------------------
Reporter: Ebenezer | Owner: nobody
Hailemariam |
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
Steps to reproduce:

1. Create a `Model` and add the following field:

`foo = models.TextField(blank=True, null=True)`

2. Create a corresponding `ModelForm`

3. Create a template to render the form

4. Load the template in a browser, leave `foo` blank and submit the form

Django will incorrectly save `foo`'s value to the DB as empty string
instead. It should be stored as `null`

--
Ticket URL: <https://code.djangoproject.com/ticket/31047>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 29, 2019, 4:26:27 PM11/29/19
to django-...@googlegroups.com
#31047: Empty models.TextField being incorrectly saved as empty string
-------------------------------------+-------------------------------------
Reporter: Ebenezer | Owner: nobody
Hailemariam |
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by inoks):

I think empty HTML textarea send the value as an empty string instead of
null/None.
The only solution may be to set `disabled` attribute for the textarea. In
that case, the value for that field will not be submitted to the server
and `null` should be saved into the DB instead of the empty string.

--
Ticket URL: <https://code.djangoproject.com/ticket/31047#comment:1>

Django

unread,
Nov 29, 2019, 5:17:31 PM11/29/19
to django-...@googlegroups.com
#31047: Empty models.TextField being incorrectly saved as empty string
-------------------------------------+-------------------------------------
Reporter: Ebenezer | Owner: nobody
Hailemariam |
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* version: 2.2 => master
* resolution: => duplicate


Comment:

This is a documented and expected behavior, see
[https://docs.djangoproject.com/en/dev/ref/models/fields/#null #null] and
[https://docs.djangoproject.com/en/dev/ref/models/fields/#blank #blank].

Duplicate of #9590.

--
Ticket URL: <https://code.djangoproject.com/ticket/31047#comment:2>

Reply all
Reply to author
Forward
0 new messages