question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to solve `Customized User` clash with `User`?

See original GitHub issue

Softwares Python: 3.6.8 Django: 2.2.2 OSX: 10.14.2 django-cognito-jwt: 0.0.3

According to #3 I have to customized my User model. Neither single one of the works. I had tried both too.

Case 1: only COGNITO_USER_MODEL

COGNITO_USER_MODEL = "cognitos.User"

Result:

SystemCheckError: System check identified some issues:

ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'User.groups'.
	HINT: Add or change a related_name argument to the definition for 'User.groups' or 'User.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
	HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'User.user_permissions'.
cognitos.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'User.groups'.
	HINT: Add or change a related_name argument to the definition for 'User.groups' or 'User.groups'.
cognitos.User.is_superuser: (models.E006) The field 'is_superuser' clashes with the field 'is_superuser' from model 'cognitos.user'.
cognitos.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
	HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'User.user_permissions'.

Case 2: Only AUTH_USER_MODEL

AUTH_USER_MODEL = "cognitos.User"

Result:

SystemCheckError: System check identified some issues:

ERRORS:
cognitos.User.is_superuser: (models.E006) The field 'is_superuser' clashes with the field 'is_superuser' from model 'cognitos.user'.

Case3: Both COGNITO_USER_MODEL and AUTH_USER_MODEL

COGNITO_USER_MODEL = "cognitos.User"
AUTH_USER_MODEL = "cognitos.User"
SystemCheckError: System check identified some issues:

ERRORS:
cognitos.User.is_superuser: (models.E006) The field 'is_superuser' clashes with the field 'is_superuser' from model 'cognitos.user'.

What is the correct approach using this library?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
elcoliecommented, Dec 5, 2019

I found the solution now. I have to startapp with customized User class

import uuid

from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin, UserManager, AbstractUser
from django.contrib.auth.validators import UnicodeUsernameValidator
from django.db import models, IntegrityError
from django.utils import timezone
from django.utils.translation import gettext_lazy as _


class CustomizedUserManager(UserManager):
    def get_or_create_for_cognito(self, payload):
        cognito_id = payload['sub']

        try:
            return self.get(cognito_id=cognito_id)
        except self.model.DoesNotExist:
            pass

        try:
            user = self.create(
                cognito_id=cognito_id,
                email=payload['email'],
                is_active=True)
        except IntegrityError:
            user = self.get(cognito_id=cognito_id)

        return user


class User(AbstractBaseUser, PermissionsMixin):
    username_validator = UnicodeUsernameValidator()

    username = models.CharField(
        _('username'),
        max_length=150,
        unique=True,
        help_text=_('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'),
        validators=[username_validator],
        error_messages={
            'unique': _("A user with that username already exists."),
        },
    )
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=150, blank=True)
    email = models.EmailField(_('email address'), blank=True)
    is_staff = models.BooleanField(
        _('staff status'),
        default=False,
        help_text=_('Designates whether the user can log into this admin site.'),
    )
    is_active = models.BooleanField(
        _('active'),
        default=True,
        help_text=_(
            'Designates whether this user should be treated as active. '
            'Unselect this instead of deleting accounts.'
        ),
    )
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)

    EMAIL_FIELD = 'email'
    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['email']

    cognito_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    objects = CustomizedUserManager()

And add AUTH_USER_MODEL = 'customized_users.User' to settings.py

1reaction
phydycommented, Sep 17, 2021

But this error is before migrations. After adding AUTH_USER_MODEL, another error comes. use , AUTH_USER_MODEL = ‘nameOfApp.nameOfModel’, should wourk just fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

About conflict resolution for custom item types | Microsoft Learn
This topic describes how to resolve conflicts for custom item types that you create in Outlook.
Read more >
Fix conflicting records errors - Google Domains Help
Conflicts with existing records on <subdomain>; Record already in use; Name conflict; Invalid record count. Before you begin. Certain records don't interact ...
Read more >
HTMD-MI2️⃣7️⃣Intune Resolve Conflicts with ... - YouTube
HTMD MI 27 Intune Resolve Conflicts with Configuration Profiles Revert Custom configuration profileshttps://youtu.be/2mXa9gV2qEgDay ...
Read more >
Empathy Mapping: The First Step in Design Thinking
Visualizing user attitudes and behaviors in an empathy map helps UX teams align ... to investigate the cause of the conflict and resolve...
Read more >
User, Group, & Division Permissions - Qualtrics
Create Idea Screening Projects: Allows users to use the Idea Screening XM Solution. Can Change Custom Solution Access Type: Allows the user to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found