Skip content comparison in create_log_entries where revision cannot be restored (#6407)

Fixes #6368
pull/6402/head
Matt Westcott 2020-09-24 18:22:16 +01:00
rodzic 0338cc37f7
commit 510e52923a
3 zmienionych plików z 26 dodań i 4 usunięć

Wyświetl plik

@ -29,6 +29,7 @@ Changelog
* Fix: Prevent focused button labels from displaying as white on white (Karran Bessen)
* Fix: Avoid showing preview button on moderation dashboard for page types with preview disabled (Dino Perovic)
* Fix: Prevent oversized buttons in moderation dashboard panel (Dan Braghis)
* Fix: `create_log_entries_from_revisions` now handles revisions that cannot be restored due to foreign key constraints (Matt Westcott)
2.10.1 (26.08.2020)

Wyświetl plik

@ -17,3 +17,4 @@ Bug fixes
* Prevent focused button labels from displaying as white on white (Karran Bessen)
* Avoid showing preview button on moderation dashboard for page types with preview disabled (Dino Perovic)
* Prevent oversized buttons in moderation dashboard panel (Dan Braghis)
* ``create_log_entries_from_revisions`` now handles revisions that cannot be restored due to foreign key constraints (Matt Westcott)

Wyświetl plik

@ -31,13 +31,33 @@ class Command(BaseCommand):
current_page_id = revision.page_id
if not PageLogEntry.objects.filter(revision=revision).exists():
current_revision_as_page = revision.as_page_object()
try:
current_revision_as_page = revision.as_page_object()
except Exception:
# restoring old revisions may fail if e.g. they have an on_delete=PROTECT foreign key
# to a no-longer-existing model instance. We cannot compare changes between two
# non-restorable revisions, although we can at least infer that there was a content
# change at the point that it went from restorable to non-restorable or vice versa.
current_revision_as_page = None
published = revision.id == revision.page.live_revision_id
if previous_revision is not None:
# Must use .specific so the comparison picks up all fields, not just base Page ones.
comparison = get_comparison(revision.page.specific, previous_revision.as_page_object(), current_revision_as_page)
has_content_changes = len(comparison) > 0
try:
previous_revision_as_page = previous_revision.as_page_object()
except Exception:
previous_revision_as_page = None
if previous_revision_as_page is None and current_revision_as_page is None:
# both revisions failed to restore - unable to determine presence of content changes
has_content_changes = False
elif previous_revision_as_page is None or current_revision_as_page is None:
# one or the other revision failed to restore, which indicates a content change
has_content_changes = True
else:
# Must use .specific so the comparison picks up all fields, not just base Page ones.
comparison = get_comparison(revision.page.specific, previous_revision_as_page, current_revision_as_page)
has_content_changes = len(comparison) > 0
if current_revision_as_page.live_revision_id == previous_revision.id:
# Log the previous revision publishing.