Skip to content

Commit 96f642f

Browse files
authored
Add config for implicit transactions to neo4j extractor (#2258)
Signed-off-by: Kristen Armes <karmes@lyft.com>
1 parent 8a6b639 commit 96f642f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

databuilder/databuilder/extractor/neo4j_extractor.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ class Neo4jExtractor(Extractor):
3535
"""NEO4J_ENCRYPTED is a boolean indicating whether to use SSL/TLS when connecting."""
3636
NEO4J_VALIDATE_SSL = 'neo4j_validate_ssl'
3737
"""NEO4J_VALIDATE_SSL is a boolean indicating whether to validate the server's SSL/TLS cert against system CAs."""
38+
NEO4J_USE_IMPLICIT_TRANSACTIONS = 'neo4j_use_implicit_transactions'
39+
"""NEO4J_USE_IMPLICIT_TRANSACTIONS is a boolean indicating whether to use implicit or explicit transactions. This
40+
is only needed when implicit transactions are required, such as for CALL {} IN TRANSACTIONS queries."""
3841

3942
DEFAULT_CONFIG = ConfigFactory.from_dict({
4043
NEO4J_MAX_CONN_LIFE_TIME_SEC: 50,
4144
NEO4J_DATABASE_NAME: neo4j.DEFAULT_DATABASE,
45+
NEO4J_USE_IMPLICIT_TRANSACTIONS: False,
4246
})
4347

4448
def init(self, conf: ConfigTree) -> None:
@@ -50,6 +54,7 @@ def init(self, conf: ConfigTree) -> None:
5054
self.graph_url = self.conf.get_string(Neo4jExtractor.GRAPH_URL_CONFIG_KEY)
5155
self.cypher_query = self.conf.get_string(Neo4jExtractor.CYPHER_QUERY_CONFIG_KEY)
5256
self.db_name = self.conf.get_string(Neo4jExtractor.NEO4J_DATABASE_NAME)
57+
self.use_implicit_transactions = self.conf.get(Neo4jExtractor.NEO4J_USE_IMPLICIT_TRANSACTIONS)
5358

5459
uri = self.conf.get_string(Neo4jExtractor.GRAPH_URL_CONFIG_KEY)
5560
driver_args = {
@@ -107,10 +112,15 @@ def _get_extract_iter(self) -> Iterator[Any]:
107112
Execute {cypher_query} and yield result one at a time
108113
"""
109114
with self.driver.session(
110-
database=self.db_name
115+
database=self.db_name,
116+
default_access_mode=neo4j.READ_ACCESS
111117
) as session:
112118
if not hasattr(self, 'results'):
113-
self.results = session.read_transaction(self._execute_query)
119+
if not self.use_implicit_transactions:
120+
self.results = session.read_transaction(self._execute_query)
121+
else:
122+
LOGGER.info('Executing query in implicit transaction %s', self.cypher_query)
123+
self.results = session.run(self.cypher_query).data()
114124

115125
for result in self.results:
116126
if hasattr(self, 'model_class'):

databuilder/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from setuptools import find_packages, setup
77

8-
__version__ = '7.5.0'
8+
__version__ = '7.5.1'
99

1010
requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
1111
'requirements.txt')

0 commit comments

Comments
 (0)