diff --git a/databuilder/extractor/neo4j_extractor.py b/databuilder/extractor/neo4j_extractor.py index c0ae42442..f149f25f1 100644 --- a/databuilder/extractor/neo4j_extractor.py +++ b/databuilder/extractor/neo4j_extractor.py @@ -67,12 +67,13 @@ def _get_driver(self) -> Any: trust = neo4j.TRUST_SYSTEM_CA_SIGNED_CERTIFICATES if self.conf.get_bool(Neo4jExtractor.NEO4J_VALIDATE_SSL) \ else neo4j.TRUST_ALL_CERTIFICATES return GraphDatabase.driver(self.graph_url, - max_connection_life_time=self.conf.get_int( + max_connection_lifetime=self.conf.get_int( Neo4jExtractor.NEO4J_MAX_CONN_LIFE_TIME_SEC), auth=(self.conf.get_string(Neo4jExtractor.NEO4J_AUTH_USER), self.conf.get_string(Neo4jExtractor.NEO4J_AUTH_PW)), encrypted=self.conf.get_bool(Neo4jExtractor.NEO4J_ENCRYPTED), - trust=trust) + #trust=trust + ) def _execute_query(self, tx: Any) -> Any: """ @@ -80,7 +81,8 @@ def _execute_query(self, tx: Any) -> Any: """ LOGGER.info('Executing query {}'.format(self.cypher_query)) result = tx.run(self.cypher_query) - return result + #return result + return [record for record in result] def _get_extract_iter(self) -> Iterator[Any]: """ diff --git a/databuilder/publisher/neo4j_csv_publisher.py b/databuilder/publisher/neo4j_csv_publisher.py index 775603adf..585889d26 100644 --- a/databuilder/publisher/neo4j_csv_publisher.py +++ b/databuilder/publisher/neo4j_csv_publisher.py @@ -13,7 +13,7 @@ from neo4j import GraphDatabase, Transaction import neo4j -from neo4j.exceptions import CypherError +from neo4j.exceptions import Neo4jError from pyhocon import ConfigFactory from pyhocon import ConfigTree from typing import Set, List @@ -132,10 +132,11 @@ def init(self, conf: ConfigTree) -> None: else neo4j.TRUST_ALL_CERTIFICATES self._driver = \ GraphDatabase.driver(conf.get_string(NEO4J_END_POINT_KEY), - max_connection_life_time=conf.get_int(NEO4J_MAX_CONN_LIFE_TIME_SEC), + max_connection_lifetime=conf.get_int(NEO4J_MAX_CONN_LIFE_TIME_SEC), auth=(conf.get_string(NEO4J_USER), conf.get_string(NEO4J_PASSWORD)), encrypted=conf.get_bool(NEO4J_ENCRYPTED), - trust=trust) + #trust=trust + ) self._transaction_size = conf.get_int(NEO4J_TRANSCATION_SIZE) self._session = self._driver.session() self._confirm_rel_created = conf.get_bool(NEO4J_RELATIONSHIP_CREATION_CONFIRM) @@ -416,7 +417,7 @@ def _execute_statement(self, if LOGGER.isEnabledFor(logging.DEBUG): LOGGER.debug('Executing statement: {} with params {}'.format(stmt, params)) - result = tx.run(str(stmt).encode('utf-8', 'ignore'), parameters=params) + result = tx.run(str(stmt), parameters=params) if expect_result and not result.single(): raise RuntimeError('Failed to executed statement: {}'.format(stmt)) @@ -452,7 +453,7 @@ def _try_create_index(self, label: str) -> None: with self._driver.session() as session: try: session.run(stmt) - except CypherError as e: + except Neo4jError as e: if 'An equivalent constraint already exists' not in e.__str__(): raise # Else, swallow the exception, to make this function idempotent. diff --git a/databuilder/task/neo4j_staleness_removal_task.py b/databuilder/task/neo4j_staleness_removal_task.py index dc1512716..0ac858270 100644 --- a/databuilder/task/neo4j_staleness_removal_task.py +++ b/databuilder/task/neo4j_staleness_removal_task.py @@ -95,10 +95,11 @@ def init(self, conf: ConfigTree) -> None: else neo4j.TRUST_ALL_CERTIFICATES self._driver = \ GraphDatabase.driver(conf.get_string(NEO4J_END_POINT_KEY), - max_connection_life_time=conf.get_int(NEO4J_MAX_CONN_LIFE_TIME_SEC), + max_connection_lifetime=conf.get_int(NEO4J_MAX_CONN_LIFE_TIME_SEC), auth=(conf.get_string(NEO4J_USER), conf.get_string(NEO4J_PASSWORD)), encrypted=conf.get_bool(NEO4J_ENCRYPTED), - trust=trust) + #trust=trust + ) def run(self) -> None: """ @@ -265,7 +266,8 @@ def _execute_cypher_query(self, start = time.time() try: with self._driver.session() as session: - return session.run(statement, **param_dict) + result = session.run(statement, **param_dict) + return [record for record in result] finally: if LOGGER.isEnabledFor(logging.DEBUG): diff --git a/setup.py b/setup.py index 35ef4b2cf..3a57c3140 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ requirements = [ - "neo4j-driver>=1.7.2,<4.0", + "neo4j==4.1.1", "pytz>=2018.4", "statsd>=3.2.1", "retrying>=1.3.3",