diff --git a/tailbone/forms/alchemy.py b/tailbone/forms/alchemy.py index 0b9af0ff..143193b0 100644 --- a/tailbone/forms/alchemy.py +++ b/tailbone/forms/alchemy.py @@ -54,10 +54,11 @@ class AlchemyForm(Object): allow_successive_creates = False - def __init__(self, request, fieldset, **kwargs): + def __init__(self, request, fieldset, session=None, **kwargs): super(AlchemyForm, self).__init__(**kwargs) self.request = request self.fieldset = fieldset + self.session = session def _get_readonly(self): return self.fieldset.readonly @@ -82,7 +83,7 @@ class AlchemyForm(Object): def save(self): self.fieldset.sync() - Session.flush() + self.session.flush() def validate(self): self.fieldset.rebind(data=self.request.params) diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 27d7a42d..685f989b 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -949,6 +949,7 @@ class MasterView(View): else: kwargs.setdefault('cancel_url', self.get_action_url('view', instance)) factory = kwargs.pop('factory', forms.AlchemyForm) + kwargs.setdefault('session', self.Session()) form = factory(self.request, fieldset, **kwargs) form.readonly = self.viewing return form