Fixes some subtle SQLAlchemy issues.