Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Centralize get_session() for backend QueryBuilders #3676

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions aiida/orm/implementation/django/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,6 @@ def get_filter_expr(self, operator, value, attr_key, is_attribute, alias=None, c
return not_(expr)
return expr

@staticmethod
def get_session():
from aiida.manage.configuration import get_config
from aiida.backends.sqlalchemy import reset_session
from aiida.backends.sqlalchemy import get_scoped_session

if get_scoped_session() is None:
config = get_config()
profile = config.current_profile
reset_session(profile)

return get_scoped_session()

def modify_expansions(self, alias, expansions):
"""
For django, there are no additional expansions for now, so
Expand Down
6 changes: 4 additions & 2 deletions aiida/orm/implementation/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ def AiidaNode(self):
from aiida.orm import Node
return Node

@abc.abstractmethod
def get_session(self):
@staticmethod
def get_session():
"""
:returns: a valid session, an instance of sqlalchemy.orm.session.Session
"""
from aiida.backends.sqlalchemy import get_scoped_session
return get_scoped_session()

@abc.abstractmethod
def modify_expansions(self, alias, expansions):
Expand Down
4 changes: 0 additions & 4 deletions aiida/orm/implementation/sqlalchemy/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from sqlalchemy.sql.expression import case, FunctionElement
from sqlalchemy.ext.compiler import compiles

import aiida.backends.sqlalchemy
from aiida.common.exceptions import InputValidationError
from aiida.common.exceptions import NotExistent
from aiida.orm.implementation.querybuilder import BackendQueryBuilder
Expand Down Expand Up @@ -126,9 +125,6 @@ def table_groups_nodes(self):
import aiida.backends.sqlalchemy.models.group
return aiida.backends.sqlalchemy.models.group.table_groups_nodes

def get_session(self):
return aiida.backends.sqlalchemy.get_scoped_session()

def modify_expansions(self, alias, expansions):
"""
In SQLA, the metadata should be changed to _metadata to be in-line with the database schema
Expand Down