Re: [Django] #35659: Document db_default behaviour before instances are saved

7 views
Skip to first unread message

Django

unread,
Aug 6, 2024, 10:14:31 PM8/6/24
to django-...@googlegroups.com
#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
--------------------------------------+------------------------------------
Comment (by Jerome Cagado):

Hello, I would like to take a shot on this issue as a new contributor.
Could you please assign it to me? Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/35659#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 6, 2024, 11:50:34 PM8/6/24
to django-...@googlegroups.com
#35659: Document db_default behaviour before instances are saved
-------------------------------------+-------------------------------------
Reporter: Markus Andresen | Owner: Jerome
Type: | Cagado
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 5.0
Severity: Normal | Resolution:
Keywords: db_default | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jerome Cagado):

* has_patch: 0 => 1
* owner: (none) => Jerome Cagado
* status: new => assigned

Comment:

Hi team,

I’ve submitted a pull request to address this issue. You can review the
changes here: https://github.com/django/django/pull/18454

Please let me know if there are any further updates needed.

Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/35659#comment:3>

Django

unread,
Aug 7, 2024, 4:44:42 AM8/7/24
to django-...@googlegroups.com
#35659: Document db_default behaviour before instances are saved
-------------------------------------+-------------------------------------
Reporter: Markus Andresen | Owner: Jerome
Type: | Cagado
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 5.0
Severity: Normal | Resolution:
Keywords: db_default | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Markus Andresen):

Hey, thanks for accepting the ticket!

> 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.

I'm aware, the reason this behaviour is problematic (if not properly
documented) is because `my_field` is assumed to be a bool since that is
the case when a BooleanField has a `default` attribute, would people
assume that `db_default` behaves differently? They might have code that
looks something like this:

{{{
my_model = MyModel
if MyModel.my_field:
do_something

# later in code
my_model.save()
}}}


Docs currently looks like this

`If both db_default and Field.default are set, default will take
precedence when creating instances in Python code. db_default will still
be set at the database level and will be used when inserting rows outside
of the ORM or when adding a new field in a migration.`

`default taking precedence in Python code` is somewhat misleading IMO,
adding a proper "disclaimer" here might be good?
--
Ticket URL: <https://code.djangoproject.com/ticket/35659#comment:4>

Django

unread,
Aug 7, 2024, 6:26:54 AM8/7/24
to django-...@googlegroups.com
#35659: Document db_default behaviour before instances are saved
-------------------------------------+-------------------------------------
Reporter: Markus Andresen | Owner: Jerome
Type: | Cagado
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 5.0
Severity: Normal | Resolution:
Keywords: db_default | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35659#comment:5>

Django

unread,
Nov 7, 2024, 3:52:28 AM11/7/24
to django-...@googlegroups.com
#35659: Document db_default behaviour before instances are saved
-------------------------------------+-------------------------------------
Reporter: Markus Andresen | Owner: Jerome
Type: | Cagado
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 5.0
Severity: Normal | Resolution:
Keywords: db_default | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ülgen Sarıkavak):

* cc: Ülgen Sarıkavak (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/35659#comment:6>
Reply all
Reply to author
Forward
0 new messages