Opened 4 years ago

Closed 4 years ago

#31047 closed Bug (duplicate)

Empty models.TextField being incorrectly saved as empty string

Reported by: Ebenezer Hailemariam Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Steps to reproduce:

  1. Create a Model and add the following field:

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

  1. Create a corresponding ModelForm
  1. Create a template to render the form
  1. 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

Change History (2)

comment:1 by Sergey Lyapustin, 4 years ago

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.

comment:2 by Mariusz Felisiak, 4 years ago

Resolution: duplicate
Status: newclosed
Version: 2.2master

This is a documented and expected behavior, see #null and #blank.

Duplicate of #9590.

Note: See TracTickets for help on using tickets.
Back to Top