hovel / pybbm

Django forum solution. Tested, documented, shipped with example project.
BSD 2-Clause "Simplified" License
225 stars 151 forks source link

`user_saved` signal handler tries to create profile, causing an IntegrityError #286

Open jantoniomartin opened 6 years ago

jantoniomartin commented 6 years ago

I have an application with a CustomProfile class which has a OneToOne relationship to Django's User model. When a new user is created, a create_profile function handles the post_save signal from the User model and creates the CustomProfile object.

In my settings I have set PYBB_PROFILE_RELATED_NAME=CustomProfile. Because of this setting, when a new user is created, the user_saved function in pybbm's signals.py tries to create a CustomProfile too, triggering an Integrity error, since the profile was already created by my own app.

If I'm not wrong, PYBB_PROFILE_RELATED_NAME is used for more thing than just creating the profile after signup. Therefore I would suggest a new setting in pybbm to enable or disable this profile creation. Something like PYBB_CREATE_PROFILE_AFTER_SIGNUP=True|False. What do you think? Should I try it and make a pull request?

DylannCordel commented 6 years ago

Maybe you could use pre_save signal on your CustomProfile to set your specific data and let pybb create the CustomProfile instance via it's user_saved function ?

jantoniomartin commented 6 years ago

My handler just creates the CustomProfile, which pybb also does, so I have modified my handler to do nothing if pybb is installed.

Nonetheless it doesn't look too elegant to me (though it solves the problem). I think that if the custom profile is part of an application, which pybb is not a fundamental part of, pybb should be able to delegate profile creation to the main application (just my opinion, of course).

DylannCordel commented 6 years ago

pybb should be able to delegate profile creation to the main application

👍 agreed