Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#21730 closed Cleanup/optimization (fixed)

Small confusion code example in documentation

Reported by: rafalp Owned by: nobody
Component: Documentation Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The code example on following page:

https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.models.CustomUser.USERNAME_FIELD

sets both unique=True and db_index=True attributes on model field, yet documentation for unique attribute claims thats not necessary:

https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.unique

"Note that when unique is True, you don’t need to specify db_index, because unique implies the creation of an index."

This gave me small scare, so I'm reporting it to bring it up to the doc maintainers attention. ;)

Change History (6)

comment:1 Changed 5 years ago by Russell Keith-Magee

Resolution: needsinfo
Status: newclosed

I'm not sure I understand - what exactly about this is scary? It's just saying that adding db_index=True is redundant if you've also specified unique=True.

Closing needsinfo; if you can suggest better language, or can provide a pointer about what exactly is "scary" about the current language, please reopen.

comment:2 Changed 5 years ago by Aymeric Augustin

Resolution: needsinfo
Status: closednew

Well it's still necessary to remove the redundant db_index. AFAIK it creates a second index that wastes space without any benefit.

comment:3 Changed 5 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:4 Changed 5 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In c717ebbfecd248d1a0ffeffa6d167109936fbe3f:

Fixed #21730 -- Removed superfluous db_index in custom auth docs

Thanks rafalp for the report.

comment:5 Changed 5 years ago by Claude Paroz <claude@…>

In 5d99cd6877377824a6a5de92475ad0572ab6fb0f:

[1.6.x] Fixed #21730 -- Removed superfluous db_index in custom auth docs

Thanks rafalp for the report.
Backport of c717ebbfec from master.

comment:6 in reply to:  1 Changed 5 years ago by rafalp

Replying to russellm:

I'm not sure I understand - what exactly about this is scary? It's just saying that adding db_index=True is redundant if you've also specified unique=True.

It gave me scare because it made me question if my model definitions are doing what I was thinking they are doing. Rest assured, its not a comment about quality of documentation or anything like that ;)

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