7

Catch the exception if the visit count rule doesn't have a page

This commit is contained in:
Kaitlyn Crawford
2018-03-09 19:20:30 +02:00
parent 241bfb5240
commit 7f5e958ee3
2 changed files with 14 additions and 0 deletions

View File

@ -6,6 +6,7 @@ from importlib import import_module
from django.apps import apps
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.sessions.models import Session
from django.db import models
from django.template.defaultfilters import slugify
@ -239,6 +240,12 @@ class VisitCountRule(AbstractBaseRule):
from wagtail_personalisation.adapters import (
get_segment_adapter, SessionSegmentsAdapter, SEGMENT_ADAPTER_CLASS)
# Django formsets don't honour 'required' fields so check rule is valid
try:
self.counted_page
except ObjectDoesNotExist:
return False
if user:
# Create a fake request so we can use the adapter
request = RequestFactory().get('/')