Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django – AttributeError: 'User' object has no attribute 'fullclean'

I am working on a Django project on the IntelliJ IDEA IDE. I am writing unit tests in the test.py file for the User model class. When running the test.py file with the command python manage.py test it throws 2 errors on the test_username_cannot_be_blank method and the test_valid_user method. The error is the same for both methods

AttributeError: ‘User’ object has no attribute ‘fullclean’.

IDEA is also giving me a Instance attribute user defined outside init warnig on line 9 of the test.py file ("self.user = User.objects.create_user()") is where the compiler warning occurs.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What exactly is causing of the AttributeError and the compiler warning?

error traceback

# test.py file
from django.test import TestCase
from django.core.exceptions import ValidationError
from .models import User


class UserModelTestCase(TestCase):
    def setUp(self):
        self.user = User.objects.create_user(
            '@johndoe',
            first_name='John',
            last_name='Doe',
            email='johndoe@example.org',
            password='Password123',
            bio='The quick brown fox jumps over the lazy dog.'
        )

    def test_valid_user(self):
        self._assert_user_is_valid()

    def test_username_cannot_be_blank(self):
        self.user.username = ''
        self._assert_user_is_invalid()

    def _assert_user_is_valid(self):
        try:
            self.user.fullclean()
        except ValidationError:
            self.fail('user should be valid')

    def _assert_user_is_invalid(self):
        with self.assertRaises(ValidationError):
            self.user.fullclean()
# models.py file
from django.db import models
from django.contrib.auth.models import AbstractUser


class User(AbstractUser):
    bio = models.TextField()

Looked on stackoverflow but could’nt find any solution to the problem.

>Solution :

You have a typo in the method name. It is full_clean.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading