Home > Software engineering >  '>' not supported between instances of 'NoneType' and 'NoneType' Ov
'>' not supported between instances of 'NoneType' and 'NoneType' Ov

Time:05-24

Hi I am getting this error in my validation check

def sefl(clean):

  start_number=self.cleaned_data.get("start_number",None)
  end_number=self.cleaned_data.get("end_number",None)
  latest_start=max(start_number, end_number)
  earliest_end = min(start_number, end_number)
  delta = (earliest_end - latest_start)   1
  if delta is None:
        raise ValidationError("overlap not allowed")

CodePudding user response:

You will need to catch the none values you are creating, like this:

def sefl(clean):
  start_number = self.cleaned_data.get("start_number", None)
  end_number = self.cleaned_data.get("end_number", None)
  if start_number is not None and end_number is not None:
      latest_start=max(start_number, end_number)
      earliest_end = min(start_number, end_bbch)
      delta = (earliest_end - latest_start)   1
      if delta is None:
            raise ValidationError("overlap not allowed")
  else:
      raise ValidationError("start_number and end_number are required")

This is because you are defining the default values for both variables to None. If at least one of them is actually None at the time of the comparison that max or min do, the issue you are encountering is raised.

There are a couple of ways around this, if you are interested. For example you could use a different default value instead of None, if there is a suitable value for that.

  • Related