Might be safer if this line was...

`if groupids and groupids[0].startswith('sg-'):`