Minor nitpick, probably debatable, but I think it's more *pythonic* to have a `try`/`except` approach (cf. permission vs forgiveness debate):

```python
try:
    roleid = roleid[0]
except KeyError:
    do_stuff()
```

It's a really minor complaint, your code works, I'm okay with that.