From f6c73f9aeb7b6d8fd519557811430d0e695e0566 Mon Sep 17 00:00:00 2001 From: Cristian Date: Mon, 7 Dec 2020 15:39:44 -0500 Subject: [PATCH] fix: Issue with oneshot command --- archivebox/extractors/__init__.py | 2 +- archivebox/index/schema.py | 8 +++++++- tests/test_oneshot.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/archivebox/extractors/__init__.py b/archivebox/extractors/__init__.py index ceef3b51..6db89f2b 100644 --- a/archivebox/extractors/__init__.py +++ b/archivebox/extractors/__init__.py @@ -111,9 +111,9 @@ def archive_link(link: Link, overwrite: bool=False, methods: Optional[Iterable[s link.history[method_name].append(result) stats[result.status] += 1 - write_search_index(link=link, texts=result.index_texts) log_archive_method_finished(result) if not skip_index: + write_search_index(link=link, texts=result.index_texts) ArchiveResult.objects.create(snapshot=snapshot, extractor=method_name, cmd=result.cmd, cmd_version=result.cmd_version, output=result.output, pwd=result.pwd, start_ts=result.start_ts, end_ts=result.end_ts, status=result.status) diff --git a/archivebox/index/schema.py b/archivebox/index/schema.py index bc3a25da..6180d3b0 100644 --- a/archivebox/index/schema.py +++ b/archivebox/index/schema.py @@ -9,6 +9,7 @@ DO NOT ADD ANY NEW FEATURES TO THIS FILE, NEW CODE GOES HERE: core/models.py __package__ = 'archivebox.index' from pathlib import Path +from django.db.utils import OperationalError from datetime import datetime, timedelta @@ -352,7 +353,12 @@ class Link: ### Archive Status Helpers @property def num_outputs(self) -> int: - return self.as_snapshot().num_outputs + try: + return self.as_snapshot().num_outputs + except OperationalError: + return sum(1 for method in self.history.keys() + for result in self.history[method] + if result.status == 'succeeded') @property def num_failures(self) -> int: diff --git a/tests/test_oneshot.py b/tests/test_oneshot.py index d586d1b1..8e4016da 100644 --- a/tests/test_oneshot.py +++ b/tests/test_oneshot.py @@ -7,7 +7,7 @@ def test_oneshot_command_exists(tmp_path, disable_extractors_dict): process = subprocess.run(['archivebox', 'oneshot'], capture_output=True, env=disable_extractors_dict) assert not "invalid choice: 'oneshot'" in process.stderr.decode("utf-8") -def test_oneshot_commad_saves_page_in_right_folder(tmp_path, disable_extractors_dict): +def test_oneshot_command_saves_page_in_right_folder(tmp_path, disable_extractors_dict): disable_extractors_dict.update({"SAVE_DOM": "true"}) process = subprocess.run(["archivebox", "oneshot", f"--out-dir={tmp_path}", "http://127.0.0.1:8080/static/example.com.html"], capture_output=True, env=disable_extractors_dict)