#35659: Document db_default behaviour before instances are saved
--------------------------------------+------------------------------------
     Reporter:  Markus Andresen       |                    Owner:  (none)
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Documentation         |                  Version:  5.0
     Severity:  Normal                |               Resolution:
     Keywords:  db_default            |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by David Sanders):

 * component:  Database layer (models, ORM) => Documentation
 * stage:  Unreviewed => Accepted
 * summary:  Unexpected Behavior(footgun) with db_default on a BooleanField
     => Document db_default behaviour before instances are saved
 * type:  Uncategorized => Cleanup/optimization

Comment:

 Thanks for the report, though I disagree with the analysis of it being
 unexpected 😊

 > There seems to be an unexpected behavior when using the db_default
 attribute on a BooleanField. The bool() evaluation when the instance is
 not saved to the database does not reflect the specified db_default value.

 It's not safe to randomly cast things without at least checking what the
 underlying type of the variable is.  Eg `bool("false") == True`.  In this
 case `my_field` is an instance of `DatabaseDefault`.

 The documentation of `DatabaseDefault` is missing. The docs could probably
 be improved to make mention of it and that field values will be of this
 type before saving to the database.

 Accepting the ticket as a docs improvement 👍
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35659#comment:1>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/010701912810b349-51ec3dda-497d-44cc-88f1-b56892676ad9-000000%40eu-central-1.amazonses.com.

Reply via email to