Чтобы связать Apas Flask Rest с БД, я должен использовать функцию def gdb (self), которую я взял отсюда: https://pypi.org/project/Flask-Neo4j/#files Проблема в том, что я всегда получаю ошибку "RuntimeError: словарь ключейизменено во время итерации "связано со строкой" self.graph_db.legacy.get_or_create_index (i_type, i) "в функции" def gdb (self): ". Есть ли способ перезаписать функцию, чтобы она успешно компилировалась?
Спасибо!
@property
def gdb(self):
"""The graph database service instance as a property, for convenience.
Note: The property will use these configuration variables
``CONNECTION_RETRY``
``RETRY_INTERVAL``
:return: the graph database service as a property
"""
retry = False
if 'CONNECTION_RETRY' in self.app.config:
retry = self.app.config['CONNECTION_RETRY']
retry_interval = 5
if 'RETRY_INTERVAL' in self.app.config:
retry_interval = self.app.config['RETRY_INTERVAL']
retry_count = 0
try:
print("flask.ext.Neo4j gdb trying to connect to DB")
host_port = ''
host_database = self.app.config['GRAPH_DATABASE']
host_port_idx = host_database.find('://')
if host_port_idx >= 0:
# extract the host and port from the host_database
host_port_idx = host_port_idx + 3
host_port = host_database[host_port_idx:]
host_port = host_port[:host_port.find('/')]
authenticate(
host_port,
self.app.config['GRAPH_USER'],
self.app.config['GRAPH_PASSWORD']
)
self.graph_db = Graph(host_database)
except SocketError as se:
log.error('SocketError: {0}'.format(se.message))
if retry:
while retry_count < 3:
log.debug('Waiting {0}secs before Connection Retry to GraphDatabaseService'.format(
retry_interval
))
time.sleep(retry_interval)
#time.sleep(1)
retry_count += 1
try:
self.graph_db = Graph(self.app.config['GRAPH_DATABASE'])
except SocketError as sse:
log.error('SocketError: {0}'.format(sse.message))
if not hasattr(self, 'index'):
self.index = {}
# add all the indexes as app attributes
if self._indexes is not None:
for i, i_type in iter(list(self._indexes.items())):
log.debug('getting or creating graph index:{0} {1}'.format(
i, i_type
))
self.index[i] = \
self.graph_db.legacy.get_or_create_index(i_type, i)
return self.graph_db