This might be easier to read as two lines:

```
self._upgrade_hooks = [item for item in self._upgrade_hooks if not item['done']]
self._upgrade_hooks.sort(key=lambda k: (k['from'], k['to']))
```