Skip to content

Commit 98f098a

Browse files
Merge pull request #92 from pitangainnovare/fix/art-errors-5
Corrige try/except em opac
2 parents 6ece982 + 3d00338 commit 98f098a

2 files changed

Lines changed: 25 additions & 24 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.5
1+
1.7.6

article/tasks.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ def task_load_article_from_opac(self, collection='scl', from_date=None, until_da
116116

117117
try:
118118
article, created = models.Article.objects.get_or_create(collection=col_obj, scielo_issn=journal.scielo_issn, pid_v2=doc.get('pid_v2'))
119+
120+
if created or force_update:
121+
article.pid_v3 = doc.get('pid_v3') or ''
122+
if not created:
123+
article.pid_v2 = doc.get('pid_v2') or ''
124+
article.publication_date = doc.get('publication_date') or ''
125+
article.default_lang = doc.get('default_language') or ''
126+
127+
try:
128+
article.publication_year = article.publication_date[:4]
129+
except IndexError:
130+
article.publication_year = ''
131+
132+
article.save()
133+
logging.info(f'Article {"created" if created else "updated"}: {article}')
134+
119135
except models.Article.MultipleObjectsReturned as e:
120136
logging.error(f'Error getting Article: {e}. Collection: {col_obj}, Journal: {journal.scielo_issn}, PIDv2: {doc.get("pid_v2")}')
121137
ArticleEvent.create(
@@ -124,29 +140,14 @@ def task_load_article_from_opac(self, collection='scl', from_date=None, until_da
124140
data=doc
125141
)
126142
continue
127-
128-
if created or force_update:
129-
article.pid_v3 = doc.get('pid_v3') or ''
130-
if not created:
131-
article.pid_v2 = doc.get('pid_v2') or ''
132-
article.publication_date = doc.get('publication_date') or ''
133-
article.default_lang = doc.get('default_language') or ''
134-
try:
135-
article.publication_year = article.publication_date[:4]
136-
except IndexError:
137-
article.publication_year = ''
138-
139-
try:
140-
article.save()
141-
logging.debug(f'Article {"created" if created else "updated"}: {article}')
142-
except DataError as e:
143-
logging.error(f'Error saving Article: {e}. Collection: {col_obj}, Journal: {journal.scielo_issn}, PIDv2: {doc.get("pid_v2")}')
144-
ArticleEvent.create(
145-
event_type=ARTICLE_EVENT_TYPE_DATA_ERROR,
146-
message=f'Error saving Article: {e}. Collection: {col_obj}, Journal: {journal.scielo_issn}, PIDv2: {doc.get("pid_v2")}',
147-
data=doc
148-
)
149-
continue
143+
except DataError as e:
144+
logging.error(f'Error saving Article: {e}. Collection: {col_obj}, Journal: {journal.scielo_issn}, PIDv2: {doc.get("pid_v2")}')
145+
ArticleEvent.create(
146+
event_type=ARTICLE_EVENT_TYPE_DATA_ERROR,
147+
message=f'Error saving Article: {e}. Collection: {col_obj}, Journal: {journal.scielo_issn}, PIDv2: {doc.get("pid_v2")}',
148+
data=doc
149+
)
150+
continue
150151

151152
page += 1
152153
if page > int(response.get('pages', 0)):

0 commit comments

Comments
 (0)