You could try this,
groups = [e for e in Group.all()] for group in groups: try: if group.mid == 3: #do_your_thing... except AttributeError: pass