Skip to content

Commit

Permalink
attribute check handled to avoid exception during module import (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerinpetergeorge committed Dec 2, 2020
1 parent 5d7a927 commit 7afb1df
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions dj_rest_auth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,19 @@ def validate_username(self, username):
return username

class Meta:
extra_fields = []
# see https://github.com/jazzband/dj-rest-auth/issues/181
# UserModel.XYZ causing attribute error while importing other
# classes from `serializers.py`. So, we need to check whether the auth model has
# the attribute or not
if hasattr(UserModel, "USERNAME_FIELD"):
extra_fields.append(UserModel.USERNAME_FIELD)
if hasattr(UserModel, "EMAIL_FIELD"):
extra_fields.append(UserModel.EMAIL_FIELD)

model = UserModel
fields = ('pk', UserModel.USERNAME_FIELD, UserModel.EMAIL_FIELD, 'first_name', 'last_name')
read_only_fields = ('email', )
fields = ('pk', *extra_fields, 'first_name', 'last_name')
read_only_fields = ('email',)


class JWTSerializer(serializers.Serializer):
Expand Down

0 comments on commit 7afb1df

Please sign in to comment.