kvesteri/wtforms-components — pull request #19 by jpvanhal (2014-09-04 10:26:10+00:00)
Title: Fix Unique validator's session check

Consider the following module:

```python
from wtforms_components import ModelForm, Unique

class UserForm(ModelForm):
name = TextField()
email = TextField(validators=[
Unique(
User.email,
get_session=lambda: db.session
)
])
```

where `db` is an instance of `flask.ext.sqlalchemy:SQLAlchemy`.
Attempting to just import the module previously raised `RuntimeError`
because session was checked in `Unique.__init__`:

```pytb
Traceback (most recent call last):
File "user_form.py", line 3, in
class UserForm(ModelForm):
File "user_form.py", line 8, in UserEditForm
get_session=lambda: db.session
File "env/lib/python3.4/site-packages/wtforms_components/validators.py", line 209, in __init__
self._check_for_session(self.column.class_)
File "env/lib/python3.4/site-packages/wtforms_components/validators.py", line 225, in _check_for_session
if not hasattr(model, 'query') and not self.get_session:
File "env/lib/python3.4/site-packages/flask_sqlalchemy/__init__.py", line 428, in __get__
return type.query_class(mapper, session=self.sa.session())
File "env/lib/python3.4/site-packages/sqlalchemy/orm/scoping.py", line 71, in __call__
return self.registry()
File "env/lib/python3.4/site-packages/sqlalchemy/util/_collections.py", line 910, in __call__
return self.registry.setdefault(key, self.createfunc())
File "env/lib/python3.4/site-packages/flask_sqlalchemy/__init__.py", line 136, in __init__
self.app = db.get_app()
File "env/lib/python3.4/site-packages/flask_sqlalchemy/__init__.py", line 809, in get_app
raise RuntimeError('application not registered on db '
RuntimeError: application not registered on db instance and no application bound to current context
```

I removed the session check from `__init__`. Now it's checked when
the `Unique` validator is actually called.