Skip to content

Commit

Permalink
Merge pull request #111 from pagreene/fix-read-db
Browse files Browse the repository at this point in the history
Fix read db
  • Loading branch information
pagreene committed Jun 3, 2020
2 parents 911b48f + a4e8932 commit a8d70f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions indra_db/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,14 @@ def delete_all(self, entry_list):
len(entry_list))
return

def get_copy_cursor(self):
"""Execute SQL queries in the context of a copy operation."""
# Prep the connection.
if self._conn is None:
self._conn = self.engine.raw_connection()
self._conn.rollback()
return self._conn.cursor()

def make_copy_batch_id(self):
"""Generate a random batch id for copying into the database.
Expand Down
3 changes: 2 additions & 1 deletion indra_db/reading/read_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ def dump_statements_to_db(self):
# Dump the duplicates into a separate to all for debugging.
self._db.copy('rejected_statements', [tpl for dlist in dups.values()
for tpl in dlist],
DatabaseStatementData.get_cols())
DatabaseStatementData.get_cols(),
commit=False)

# Add the agents for the accepted statements.
logger.info("Uploading agents to the database.")
Expand Down
2 changes: 1 addition & 1 deletion indra_db/util/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def insert_raw_agents(db, batch_id, stmts=None, verbose=False,
ref_tuples = []
mod_tuples = []
mut_tuples = []
cur = db._conn.cursor()
if stmts is None:
s_col = 'json'
stmt_dict = None
else:
s_col = 'uuid'
stmt_dict = {s.uuid: s for s in stmts}

cur = db.get_copy_cursor()
cur.execute(f'SELECT id, {s_col} FROM raw_statements WHERE batch_id=%s',
(batch_id,))
if verbose:
Expand Down

0 comments on commit a8d70f3

Please sign in to comment.