from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend

User = get_user_model()


class HelloBaseIDBackend(ModelBackend):
    def authenticate(self, username=None):
        try:
            user = User.objects.filter(username=username)[0]
        except IndexError:
            return None
        else:
            return user

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend

User = get_user_model()


class HelloBaseIDBackend(ModelBackend):
    def authenticate(self, username=None):
        try:
            user = User.objects.filter(username=username)[0]
        except IndexError:
            return None
        else:
            return user

    def get_user(self, user_id):
        return User.objects.get(pk=user_id)

Remove the try/except clause from get_user().
Remove the try/except clause from get_user().

It doesn't seem like the code will -ever- hit the except clause as the
method that calls this has fallbacks of its own.

  from django.contrib.auth import get_user_model
  from django.contrib.auth.backends import ModelBackend
  
  User = get_user_model()
  
  
  class HelloBaseIDBackend(ModelBackend):
      def authenticate(self, username=None):
          try:
              user = User.objects.filter(username=username)[0]
          except IndexError:
              return None
          else:
              return user
  
      def get_user(self, user_id):
-         try:
-             return User.objects.get(pk=user_id)
+         return User.objects.get(pk=user_id)
-         except User.DoesNotExist:
-             return None
  
Remove the try/except clause from get_user().
## Code Before:
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend

User = get_user_model()


class HelloBaseIDBackend(ModelBackend):
    def authenticate(self, username=None):
        try:
            user = User.objects.filter(username=username)[0]
        except IndexError:
            return None
        else:
            return user

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

## Instruction:
Remove the try/except clause from get_user().
## Code After:
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend

User = get_user_model()


class HelloBaseIDBackend(ModelBackend):
    def authenticate(self, username=None):
        try:
            user = User.objects.filter(username=username)[0]
        except IndexError:
            return None
        else:
            return user

    def get_user(self, user_id):
        return User.objects.get(pk=user_id)
