Sqlalchemy fixes after develop branch merged

All the tests should be passing now. I have added a try/except in `document_etag` function:

```python
try:
    h.update(dumps(value, sort_keys=True, cls=app.data.json_encoder_class).encode('utf-8'))
except RuntimeError: # in some cases we don't have app initialized
    h.update(dumps(value, sort_keys=True))
```
I was not able to understand the magic in which flask is getting the app - one of the tests was failing because of that.