Opened 8 years ago

Closed 8 years ago

#18093 closed New feature (fixed)

AnonymousUser should have a 'pk' attribute

Reported by: Chris Lamb Owned by:
Component: contrib.auth Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


I like the "pk" field on models as it means I can refer to the primary key of any instance without having to know some implementation detail about the model.

However, this idea breaks down with the AnonymousUser pseudo-model; it has an id element (of None) but it has no pk element. This requires some special-casing which I would like to be rid of.

Sure, it's not a real model. But if AnonymousUser has an 'id' element and can exist where a "real" auth.User may exist, it might as well have an 'pk' too.

Patch is trivial.

Attachments (1)

18093.diff (871 bytes) - added by Stephen Muss 8 years ago.
Patch with test

Download all attachments as: .zip

Change History (9)

comment:1 Changed 8 years ago by Thomas Güttler

Has patch: unset

If the patch is trivial, please add it to this ticket. I remove "has patch".

comment:2 Changed 8 years ago by Preston Holmes

Component: Uncategorizedcontrib.auth
Summary: AnonymousUser should have a 'pk' elementAnonymousUser should have a 'pk' attribute
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature

While from a purity point of view - "primary key" pk implies a database persistence, the truth is that in Django models, pk is more removed from the actual db column than id is.

However I can't imagine any major negative impacts from also setting pk=None in AnonymousUser

comment:3 Changed 8 years ago by Stephen Muss

Has patch: set
Owner: changed from nobody to Stephen Muss
Status: newassigned

comment:4 Changed 8 years ago by Claude Paroz

Needs tests: set

comment:5 Changed 8 years ago by Stephen Muss

Owner: Stephen Muss deleted
Status: assignednew
Version: 1.4SVN

Changed 8 years ago by Stephen Muss

Attachment: 18093.diff added

Patch with test

comment:6 Changed 8 years ago by Stephen Muss

Needs tests: unset

I've added another patch with a test included. If the test is in the wrong place please let me know how I can add it in the right location. Thanks.

comment:7 Changed 8 years ago by Anssi Kääriäinen

Triage Stage: AcceptedReady for checkin

Looks good to me.

comment:8 Changed 8 years ago by Aymeric Augustin

Resolution: fixed
Status: newclosed

Fixed #18093 -- Added a pk to AnonymousUser.

Changeset: b1155adcde0282a533a5ad1d7220adbd52011230

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