Opened 4 years ago

Closed 4 years ago

#18093 closed New feature (fixed)

AnonymousUser should have a 'pk' attribute

Reported by: lamby 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 smuss 4 years ago.
Patch with test

Download all attachments as: .zip

Change History (9)

comment:1 Changed 4 years ago by guettli

  • Has patch unset
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 4 years ago by ptone

  • Component changed from Uncategorized to contrib.auth
  • Summary changed from AnonymousUser should have a 'pk' element to AnonymousUser should have a 'pk' attribute
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to New 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 4 years ago by smuss

  • Has patch set
  • Owner changed from nobody to smuss
  • Status changed from new to assigned

comment:4 Changed 4 years ago by claudep

  • Needs tests set

comment:5 Changed 4 years ago by smuss

  • Owner smuss deleted
  • Status changed from assigned to new
  • Version changed from 1.4 to SVN

Changed 4 years ago by smuss

Patch with test

comment:6 Changed 4 years ago by smuss

  • 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 4 years ago by akaariai

  • Triage Stage changed from Accepted to Ready for checkin

Looks good to me.

comment:8 Changed 4 years ago by Aymeric Augustin

  • Resolution set to fixed
  • Status changed from new to closed

Fixed #18093 -- Added a pk to AnonymousUser.

Changeset: b1155adcde0282a533a5ad1d7220adbd52011230

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