[Django] #24665: Model field relational attributes are None by default, not False

79 views
Skip to first unread message

Django

unread,
Apr 19, 2015, 5:44:50 PM4/19/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: pirosb3
Type: Bug | Status: new
Component: Database | Version: 1.8
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The docs state that the relational attributes, such as `many_to_many`,
`one_to_many`, etc should be `False` by default
(https://docs.djangoproject.com/en/1.8/ref/models/fields/#attributes-for-
fields-with-relations). In practice they are `None` though.

According to Daniel on IRC they should be `False` not `None` (i.e. the
documentation is correct).

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

Django

unread,
Apr 20, 2015, 8:17:07 AM4/20/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: yoongkang
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by yoongkang):

* owner: pirosb3 => yoongkang
* status: new => assigned


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

Django

unread,
Apr 20, 2015, 10:00:30 AM4/20/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: yoongkang
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by pirosb3):

yoongkang, are you doing this?

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

Django

unread,
Apr 20, 2015, 10:56:49 AM4/20/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: yoongkang
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by yoongkang):

pirosb3, sorry I think I must have mixed this up with a different issue.
How do I assign it back to you?

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

Django

unread,
Apr 20, 2015, 2:40:00 PM4/20/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121

Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by honya121):

* owner: pirosb3 => honya121


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:4>

Django

unread,
Apr 20, 2015, 5:10:17 PM4/20/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by honya121):

It seems that the relational attributes are `None` only for non-relational
fields (`Field.is_relation=False`). For relational fields these attributes
are `False` or `True`. This is right behaviour according to the
documentation (the values should only be meaningful if
`Field.is_relation=True`), but it is possible, that I tested it badly. So
there are 2 options:
a) keep default relational values in the non-relational fields `None`
b) set default relational values for ALL fields to `False`

For both options, it would be good to write what values are default even
for fields with `Field.is_relation=False`, instead of writing that these
fields will have unmeaningful values.

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

Django

unread,
Apr 20, 2015, 5:46:17 PM4/20/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by MarkusH):

Hi honya121, in my opinion you should go forward with option b. I don't
understand what you mean with your last sentence.

--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:6>

Django

unread,
Apr 21, 2015, 2:04:32 AM4/21/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by honya121):

Hi, ok, I'll do the b) option. The last sentence is about documentation.
Sorry, I forgot to mention that. Anyway, in the documentation, there
should be also mentioned, that the relational attributes will be `False`
for non-relational fields.

--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:7>

Django

unread,
Apr 23, 2015, 9:23:27 AM4/23/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/4540 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:8>

Django

unread,
Apr 28, 2015, 12:33:41 PM4/28/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by timgraham):

I'd like to better understand the rationale for this change. In my mind,
`None` for non-relational fields seems like it may make debugging easier,
e.g. if you find a `None` value, then you'll know you forgot to check
`is_relation`.

--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:9>

Django

unread,
Apr 28, 2015, 12:36:13 PM4/28/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by carljm):

I agree with timgraham. It seems entirely sensible to me to have the
relation-cardinality attributes be `None` (as in, neither `True` nor
`False` because they are not even applicable in the first place) for non-
relational fields. I don't see the rationale for changing them to `False`.

--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:10>

Django

unread,
Apr 28, 2015, 12:49:15 PM4/28/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by MarkusH):

Either way makes sense in my eyes. E.g. "Am I a one_to_many field?" --
"No" --> `False`. In that case I think we still need to update the docs.

--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:11>

Django

unread,
Apr 28, 2015, 1:02:17 PM4/28/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by timgraham):

{{{
#!diff
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index 01ff654..f8144c1 100644
--- a/docs/ref/models/fields.txt
+++ b/docs/ref/models/fields.txt
@@ -1883,7 +1883,7 @@ Attributes for fields with relations

These attributes are used to query for the cardinality and other details
of a
relation. These attribute are present on all fields; however, they will
only
-have meaningful values if the field is a relation type
+have boolean values (rather than ``None``) if the field is a relation
type
(:attr:`Field.is_relation=True <Field.is_relation>`).

.. attribute:: Field.many_to_many
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:12>

Django

unread,
Apr 29, 2015, 5:22:55 PM4/29/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* status: assigned => closed
* resolution: => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:13>

Django

unread,
Apr 29, 2015, 8:40:56 PM4/29/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* resolution: invalid => fixed


Comment:

In [changeset:"2b086229a2a6c786e32da37b6b122c2cc894450f" 2b08622]:
{{{
#!CommitTicketReference repository=""
revision="2b086229a2a6c786e32da37b6b122c2cc894450f"
Fixed #24665 -- Clarified model field flag defaults.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:14>

Django

unread,
Apr 29, 2015, 8:41:17 PM4/29/15
to django-...@googlegroups.com
#24665: Model field relational attributes are None by default, not False
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: honya121
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"afae8ff916e85488a31384a681cd4d4fedea58b8" afae8ff]:
{{{
#!CommitTicketReference repository=""
revision="afae8ff916e85488a31384a681cd4d4fedea58b8"
[1.8.x] Fixed #24665 -- Clarified model field flag defaults.

Backport of 2b086229a2a6c786e32da37b6b122c2cc894450f from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24665#comment:15>

Reply all
Reply to author
Forward
0 new messages