Opened 12 years ago

Closed 12 years ago

#18093 closed New feature (fixed)

AnonymousUser should have a 'pk' attribute

Reported by: Chris Lamb Owned by:
Component: contrib.auth Version: dev
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

Description

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 12 years ago.
Patch with test

Download all attachments as: .zip

Change History (9)

comment:1 by Thomas Güttler, 12 years ago

Has patch: unset

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

comment:2 by Preston Holmes, 12 years ago

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 by Stephen Muss, 12 years ago

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

comment:4 by Claude Paroz, 12 years ago

Needs tests: set

comment:5 by Stephen Muss, 12 years ago

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

by Stephen Muss, 12 years ago

Attachment: 18093.diff added

Patch with test

comment:6 by Stephen Muss, 12 years ago

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 by Anssi Kääriäinen, 12 years ago

Triage Stage: AcceptedReady for checkin

Looks good to me.

comment:8 by Aymeric Augustin, 12 years ago

Resolution: fixed
Status: newclosed

Fixed #18093 -- Added a pk to AnonymousUser.

Changeset: b1155adcde0282a533a5ad1d7220adbd52011230

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