Skip to content
Snippets Groups Projects
Commit 6f71857a authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'fix-index-hidden' into 'master'

Prevent AttributeError when indexing hidden elements without zones

See merge request !612
parents b0d26503 7816e987
No related branches found
No related tags found
1 merge request!612Prevent AttributeError when indexing hidden elements without zones
......@@ -109,7 +109,10 @@ class ESElement(Document):
def from_model(cls, instance):
from arkindex.documents.models import Element, Transcription
hidden_children = Element.objects.get_descending(instance.id).filter(type__hidden=True)
hidden_children = Element \
.objects \
.get_descending(instance.id) \
.filter(type__hidden=True, zone__isnull=False)
transcriptions = chain(
instance.transcriptions.all(),
*[
......
from unittest.mock import patch
from arkindex_common.enums import MetaType
from arkindex_common.enums import MetaType, TranscriptionType
from arkindex.project.tests import FixtureAPITestCase
from arkindex.project.polygon import Polygon
from arkindex.project.elastic import ESElement
from arkindex.documents.models import DataSource
from arkindex.documents.dates import DateType, InterpretedDate
......@@ -43,3 +45,24 @@ class TestESDocuments(FixtureAPITestCase):
element.metadatas.create(type=MetaType.Reference, name='ref.', value='123ABC')
es_document = ESElement.from_model(element)
self.assertCountEqual(es_document.references, ['123abc'])
def test_hidden_no_zone(self):
"""
Ensure hidden elements without zones are ignored when indexing an element's hidden children
"""
page = self.corpus.elements.get(name='Volume 1, page 1r')
self.assertTrue(page.transcriptions.exists())
surface = self.corpus.elements.create(
type=self.corpus.types.get(slug='surface'),
name='/dev/null',
zone=None,
)
surface.add_parent(page)
surface.transcriptions.create(
type=TranscriptionType.Word,
text='invisible transcription',
zone=page.zone.image.zones.create(polygon=Polygon.from_coords(0, 0, 1, 1)),
source=DataSource.objects.get(slug='test'),
)
texts = [tr['text'] for tr in ESElement.from_model(page).to_dict()['transcriptions']]
self.assertNotIn('invisible transcription', texts)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment