<commit_before>from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User

class LazySignupBackend(ModelBackend):

    def authenticate(self, username=None):
        users = [u for u in User.objects.filter(username=username)
                 if not u.has_usable_password()]
        if len(users) != 1:
            return None
        return users[0]

    def get_user(self, user_id):
        # Annotate the user with our backend so it's always available,
        # not just when authenticate() has been called. This will be
        # used by the is_lazy_user filter.
        user = super(LazySignupBackend, self).get_user(user_id)
        user.backend = 'lazysignup.backends.LazySignupBackend'
        return user<commit_msg>don't attach a backend property to user objects if the session user id is invalid and the user is None<commit_after>from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User

class LazySignupBackend(ModelBackend):

    def authenticate(self, username=None):
        users = [u for u in User.objects.filter(username=username)
                 if not u.has_usable_password()]
        if len(users) != 1:
            return None
        return users[0]

    def get_user(self, user_id):
        # Annotate the user with our backend so it's always available,
        # not just when authenticate() has been called. This will be
        # used by the is_lazy_user filter.
        user = super(LazySignupBackend, self).get_user(user_id)
        if user:
            user.backend = 'lazysignup.backends.LazySignupBackend'
        return user
{'fraction_non_alphanumeric': 0.0757020757020757, 'fraction_numerical': 0.002442002442002442, 'mean_word_length': 2.8294392523364484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5794195', 'n_tokens_mistral': 471, 'n_tokens_neox': 467, 'n_words': 148}