Issue with validators.py

Issue #48 resolved
Harry Atkinson created an issue

obj_id having multiple variables types of unicode or int. I have done some testing and if you replace the following function at line 31 with this it should work:

def check_duplicate(self, value, obj_id):
    comparer = {self.attribute_to_compare: value}
    result = self.object_class.get_filter_by(**comparer).first()
    if type(obj_id) is int:
        obj_id = str(obj_id)
    if result is None:
        return true
    elif obj_id.isdigit() and result.id == int(obj_id):
        return True
    else:
        return False

Comments (4)

  1. Richard Nguyen

    For this issue, it caused an Error 500 whenever we clicked "submit" on the edit Case page.

    Our workaround was (starting from line 31 in foreman/forms/validators.py):

        def check_duplicate(self, value, obj_id):
            comparer = {self.attribute_to_compare: value}
            result = self.object_class.get_filter_by(**comparer).first()
            if result is None:
                return True                 #Note: the following 2 statements are custom
            elif isinstance(obj_id, basestring) and obj_id.isdigit() and result.id == int(obj_id):
                return True
            elif result.id == obj_id:
                return True
            else:
                return False
    
  2. Log in to comment