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

UserProfileSerializer doesn't handle foreignKey fields? #106

Closed
jonas87 opened this issue Mar 31, 2020 · 2 comments · Fixed by #107
Closed

UserProfileSerializer doesn't handle foreignKey fields? #106

jonas87 opened this issue Mar 31, 2020 · 2 comments · Fixed by #107

Comments

@jonas87
Copy link
Contributor

jonas87 commented Mar 31, 2020

So I have a foreignKey on one of the fields of my User model (did this by subclassing AbstractUser and pointing AUTH_USER_MODEL in settings.py to this User model). These extra fields are showing up correctly in my calls to "accounts/register/". However when I'm submitting my registration form I'm submitting an integer that represents the primary key for this foreignKey field and I get the following error:
Cannot assign "4": "User.user_type" must be a "UserType" instance.

The error happens in _build_initial_user() on line 175 of rest_registration/api/serializers.py because it's trying to construct an instance of the usermodel there with self.initial_data which holds an integer for the ForeignKey field.

@apragacz
Copy link
Owner

apragacz commented Apr 2, 2020

Hi @jonas87
Just to let you know on the current situation: I'm currently working on a test which will reproduce the issue. Unfortunately I have to do some refactors so I can start write tests the new pytesty way. I hope I will be able to do that till tomorrow.

After that, we could work on the MR you provided (so we can be sure that it indeed fixes the issue by having a reproduced example in the test).

apragacz added a commit that referenced this issue Apr 4, 2020
This test should be unskipped when issue #106 will be resolved
apragacz added a commit that referenced this issue Apr 4, 2020
This test should be unskipped when issue #106 will be resolved
@apragacz
Copy link
Owner

apragacz commented Apr 4, 2020

@jonas87 I dropped the test in master, it is currently skipped (as it fails). Let's continue the discussion in PR #107.

apragacz added a commit that referenced this issue Apr 4, 2020
Changes:

*   Fixed password validation to support users with foreign keys (issue #106)
*   Added `"NOT_AUTHENTICATED_PERMISSION_CLASSES"` setting (PR #105)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants