could be written in more Pythonic [EAFP](https://docs.python.org/3.4/glossary.html) instead of LBYL
```Python
try:
    logger.error("Error sorting with function %s" % order_by.func_name)
except AttributeError:
    logger.error("Error sorting with function %r" % order_by)
```
Overall I'm not sure such special handling of the function representation is necessary, IMHO `' function {}'.format(func)` is informative enough.