Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit c385482f authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Catch exception inserting the record in the database.

parent ce7d9f72
......@@ -8,6 +8,7 @@ import traceback
from automaton import Automaton
from base import (family_name_fr,
format_author_fr,
learn_my_authors,
MSG_CRASH,
MSG_FIX_ORIGIN,
MSG_IN_DB,
......@@ -285,29 +286,36 @@ class Articles(Automaton):
# try to improve the rescue list for CPPM authors
if not self.dry_run:
db.publications.insert(authors=record.authors(),
authors_institute=my_authors,
first_author=first_author,
id_categories=self.id_category,
id_collaborations=id_collaboration,
id_projects=self.id_project,
id_publishers=id_publisher,
id_status=UNDEF_ID,
id_teams=self.id_team,
origin=oai_url,
pages=pages,
preprint=preprint_number,
publication_url=publication_url,
submitted=submitted,
title=title,
volume=volume,
year=year)
learn_my_authors(db,
authors=record.my_authors,
id_project=self.id_project,
id_team=self.id_team,
year=year)
self.logs[-1].load(MSG_LOAD, year)
return 1
ret = self._insert_in_db(log_year=year,
authors=record.authors(),
authors_institute=my_authors,
first_author=first_author,
id_categories=self.id_category,
id_collaborations=id_collaboration,
id_projects=self.id_project,
id_publishers=id_publisher,
id_status=UNDEF_ID,
id_teams=self.id_team,
origin=oai_url,
pages=pages,
preprint=preprint_number,
publication_url=publication_url,
submitted=submitted,
title=title,
volume=volume,
year=year)
if ret == 1:
learn_my_authors(db,
authors=record.my_authors,
id_project=self.id_project,
id_team=self.id_team,
year=year)
self.logs[-1].load(MSG_LOAD, year)
else:
ret = 1
self.logs[-1].load(MSG_LOAD, year)
return ret
......@@ -15,13 +15,14 @@ from invenio_tools import (CheckAndFix,
REG_OAI)
from msg import Msg
from msgcollection import MsgCollection
from plugin_dbui import get_create_id, get_id, UNDEF_ID
from plugin_dbui import CALLBACK_ERRORS, get_create_id, get_id, UNDEF_ID
MSG_NO_CAT = 'Select a "category" !!!'
MSG_NO_PROJECT = 'Select a "project" !!!'
MSG_NO_TEAM = 'Select a "team" !!!'
MSG_NSERT_FAIL = "Fail to insert the new record in the database."
MSG_NO_OAI = "Reject no OAI identifier"
MSG_WELL_FORM_OAI = "Reject OAI is not well formed"
......@@ -114,6 +115,40 @@ class Automaton(object):
controller=self.controller,
id_categories=self.id_category)
def _insert_in_db(self, log_year="", **fields):
"""Insert the record in the database, handling database exception.
@type log_year: unicode
@param log_year: year of the record for the log
@type **fields: dict
@param **fields:
@rtype: int
@return: one when the record is inserted / updated in the database
zero otherwise.
"""
db = self.db
try:
rec_id = db.publications.insert (**fields)
return 1
# operation can be rejected by the database
except Exception as dbe:
self.logs[-1].reject(dbe.message, year)
# operation can be reject by callbacks table._before_insert
if not rec_id:
msg = MSG_NSERT_FAIL
if CALLBACK_ERRORS in db.publications:
msg = db.publications._callback_errors
self.logs[-1].reject(msg, year)
return 0
def _is_record_in_db(self, rec_id, title):
"""Return C{True} if the record is already in the database.
The search is based on the origin field.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment