Opened 4 years ago

Closed 4 years ago

#30401 closed Cleanup/optimization (wontfix)

Clarification about when a default value is assigned to a ModelField

Reported by: Vinicius Assef Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The documentation says in at the first paragraph:

The default value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.

My suggestion is to change the last word above, from "created" to "instantiated" or to "instantiated in memory".

"Created" is confusing with QuerySet.create() method, leading to the misunderstanding about when the default value is assigned to field.

I myself misunderstood I could use the traditional approach to check if performing an insert or an update in with if is None when my pk is an UUIDField with default=uuid.uuid4.

Change History (1)

comment:1 Changed 4 years ago by Mariusz Felisiak

Resolution: wontfix
Status: newclosed
Version: 2.2master

Thanks for the report, however it is not confusing IMO. Moreover an extra clarification is in the same paragraph

"The default value is used when new model instances are created and a value isn't provided for the field. When the field is a primary key, the default is also used when the field is set to None."

We try to avoid wording changes unless it's a big problem as it creates extra work for documentation translators.

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