code: def raise_on_duplicate(self, attrname):
          
          if getattr(self, attrname):
              with transaction.atomic():
                  error_msg = (
                      'Cannot {{action}} registered subject with a duplicate '
                      '\'{}\'. Got {}.'.format(attrname, getattr(self, attrname)))
                  try:
                      obj = self.__class__.objects.exclude(
                          **{'pk': self.pk} if self.id else {}).get(
                              **{attrname: getattr(self, attrname)})
                      if not self.id:
                          raise RegisteredSubjectError(
                              error_msg.format(action='insert'))
                      elif self.subject_identifier_is_set() and obj.id != self.id:
                          raise RegisteredSubjectError(
                              error_msg.format(action='update'))
                      else:
                          raise RegisteredSubjectError(
                              error_msg.format(action='update'))
                  except self.__class__.DoesNotExist:
                      pass
docs: Checks if the subject identifier (or other attr) is in use,
          for new and existing instances.