This is going to throw a KeyError if 'UID' is not in dt. Use dt.get('UID')

However, it looks like you're catching KeyError and ResourceNotFound error, which the original line 435 would have thrown if UID was not in dt...