diff --git a/Tst/codeblockreusefeature/codeblockreuse.py b/Tst/codeblockreusefeature/codeblockreuse.py index 95da74d80a5ea042a52f6345d8532dc6e22db2e5..cd03145b366f6be2b57889d48498a2e30d24aebe 100755 --- a/Tst/codeblockreusefeature/codeblockreuse.py +++ b/Tst/codeblockreusefeature/codeblockreuse.py @@ -257,8 +257,9 @@ class CBRSearch(Gtk.Box): super().__init__(*args, **kwargs) self.app_win = app_win self.logger = logger - with db_schema.session_scope() as session: - self.session = session + + # with db_schema.session_scope() as session: + # self.session = session self._filter_searchstring = '' self._filter_type_snippet = None @@ -769,11 +770,10 @@ class CBRSearch(Gtk.Box): Loads the data from the database. The filter properties are used to build the SQL query. """ self.logger.debug('Loading data from the database') - self.session.commit() # this updates the session instantiated in the class init if self.filter_searchstring != '': - self.data = db_interaction.query_using_textsearch(session=self.session, expressions=self.filter_searchstring) + self.data = db_interaction.query_using_textsearch(expressions=self.filter_searchstring) else: - self.data = db_interaction.query_get_all_entries(self.session) + self.data = db_interaction.query_get_all_entries() self.load_data_into_liststore(self.data) def reload_data(self): diff --git a/Tst/codeblockreusefeature/db_interaction.py b/Tst/codeblockreusefeature/db_interaction.py index 9a9412ff34906c6617be35a0ad19aeab05adf54f..62b1e9c6dc318091ea3d2007fd924a1d5e3c2a80 100644 --- a/Tst/codeblockreusefeature/db_interaction.py +++ b/Tst/codeblockreusefeature/db_interaction.py @@ -2,8 +2,10 @@ import db_schema from db_schema import CodeBlock -def query_get_all_entries(session): - data = session.query(CodeBlock).all() +def query_get_all_entries(): + with db_schema.session_scope() as session: + data = session.query(CodeBlock).all() + session.expunge_all() return data @@ -27,16 +29,19 @@ def delete_db_row(id): return -def query_using_textsearch(session, expressions): - data = session.query(CodeBlock).filter(CodeBlock.description.contains(expressions)).all() +def query_using_textsearch(expressions): + with db_schema.session_scope() as session: + data = session.query(CodeBlock).filter(CodeBlock.description.contains(expressions)).all() + session.expunge_all() return data -def query_code_types(session): - data = session.query(CodeBlock.code_type).group_by(CodeBlock.code_type).all() +def query_code_types(): + with db_schema.session_scope() as session: + data = session.query(CodeBlock.code_type).group_by(CodeBlock.code_type).all() + session.expunge_all() return data if __name__ == '__main__': - with db_schema.session_scope() as session: - query_code_types(session) + query_code_types()