Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jantoniomartin opened this issue Feb 9, 2018 · 3 comments

Comments

@jantoniomartin
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

DylannCordel commented Feb 10, 2018

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

👍 agreed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants