Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#17318 closed Bug (invalid)

'Topic authentication', section 'Storing additional information about users' there is bug in the code

Reported by: supreet.sethi@… Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords: UserProfile
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In the example code for creating profile using post_save event of User. The code is written thus

def create_user_profile(sender, instance, created, **kwargs):
    if created:

Whereas it should be thus:

def create_user_profile(sender, instance, created, **kwargs):
    if created:

Otherwise it generates "IntegrityError: column user_id is not unique" error.

Change History (2)

comment:1 Changed 6 years ago by Karen Tracey

Resolution: invalid
Status: newclosed

The proposed change is unnecessary (create() already saves the new object to the DB) and would not do anything to fix an IntegrityError. You'd get an IntegrityError if somehow this create_user_profile was called with create set to True for some user instance where there was already a UserProfile object for it in the DB. I'm not sure how that would have happened, but tacking .save() onto that existing line of code wouldn't fix that problem.

comment:2 Changed 6 years ago by bwanamarko@…

as stated in the Status comment by @kmtracy m it raises the integrity exception because the UserProfile is already created changing the create to get_or_create solves the problem.

def create_user_profile(sender, instance, created, **kwargs):
    if created:
Note: See TracTickets for help on using tickets.
Back to Top