Commit 8bc5e9cd authored by Paul Brown's avatar Paul Brown

sqla - prevent AjaxSelectField autoflush while populating model

parent d84945cf
...@@ -20,8 +20,7 @@ app.config['SECRET_KEY'] = '123456790' ...@@ -20,8 +20,7 @@ app.config['SECRET_KEY'] = '123456790'
app.config['DATABASE_FILE'] = 'sample_db.sqlite' app.config['DATABASE_FILE'] = 'sample_db.sqlite'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + app.config['DATABASE_FILE'] app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + app.config['DATABASE_FILE']
app.config['SQLALCHEMY_ECHO'] = True app.config['SQLALCHEMY_ECHO'] = True
session_options = dict(autoflush=False) db = SQLAlchemy(app)
db = SQLAlchemy(app, session_options=session_options)
# Create models # Create models
......
...@@ -55,6 +55,8 @@ class QueryAjaxModelLoader(AjaxModelLoader): ...@@ -55,6 +55,8 @@ class QueryAjaxModelLoader(AjaxModelLoader):
return (getattr(model, self.pk), as_unicode(model)) return (getattr(model, self.pk), as_unicode(model))
def get_one(self, pk): def get_one(self, pk):
# prevent autoflush from occuring during populate_obj
with self.session.no_autoflush:
return self.session.query(self.model).get(pk) return self.session.query(self.model).get(pk)
def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE): def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment