diff --git a/HISTORY.rst b/HISTORY.rst index f90822d6cb..55a56f1dbe 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,8 @@ * Make sure all key used as input for the cache key hash are bytes and not unicode. GitLab issue #520. Thanks to TheOneValen @TheOneValen for the report. +* Ignore document stub from the index mirror. GitLab issue + #520. Thanks to TheOneValen @TheOneValen for the report. 3.1.6 (2018-10-09) ================== diff --git a/docs/releases/3.1.7.rst b/docs/releases/3.1.7.rst index 7c6db16575..bbc8eca10b 100644 --- a/docs/releases/3.1.7.rst +++ b/docs/releases/3.1.7.rst @@ -13,6 +13,8 @@ Changes * Make sure all key used as input for the cache key hash are bytes and not unicode. GitLab issue #520. Thanks to TheOneValen @TheOneValen for the report. +* Ignore document stub from the index mirror. GitLab issue + #520. Thanks to TheOneValen @TheOneValen for the report. Removals diff --git a/mayan/apps/mirroring/filesystems.py b/mayan/apps/mirroring/filesystems.py index 51b7d45e81..0a42e788ab 100644 --- a/mayan/apps/mirroring/filesystems.py +++ b/mayan/apps/mirroring/filesystems.py @@ -80,7 +80,9 @@ class IndexFilesystem(Operations): if access_only: return True else: - return Document.objects.get(pk=document_pk) + return Document.objects.get( + is_stub=False, pk=document_pk + ) for count, part in enumerate(parts[1:]): try: @@ -93,7 +95,9 @@ class IndexFilesystem(Operations): else: try: if node.index_template_node.link_documents: - document = node.documents.get(label=part) + document = node.documents.get( + is_stub=False, label=part + ) logger.debug( 'path %s is a valid file path', path ) @@ -203,7 +207,7 @@ class IndexFilesystem(Operations): # Documents if node.index_template_node.link_documents: - queryset = node.documents.values('label').exclude( + queryset = node.documents.filter(is_stub=False).values('label').exclude( label__contains='/' ) diff --git a/mayan/apps/mirroring/tests/test_filesystems.py b/mayan/apps/mirroring/tests/test_filesystems.py index 7ccafec4c3..1f9dad3220 100644 --- a/mayan/apps/mirroring/tests/test_filesystems.py +++ b/mayan/apps/mirroring/tests/test_filesystems.py @@ -7,6 +7,7 @@ from fuse import FuseOSError from django.test import override_settings from common.tests import BaseTestCase +from documents.models import Document from documents.tests import DocumentTestMixin from document_indexing.tests import DocumentIndexingTestMixin @@ -133,3 +134,26 @@ class IndexFilesystemTestCase(DocumentIndexingTestMixin, DocumentTestMixin, Base self.assertEqual( list(index_filesystem.readdir('/', ''))[2:], [] ) + + def test_ignore_stub_documents(self): + self._create_index() + + self.index.node_templates.create( + parent=self.index.template_root, expression=TEST_NODE_EXPRESSION, + link_documents=True + ) + + self.document = Document.objects.create( + document_type=self.document_type, label='document_stub' + ) + index_filesystem = IndexFilesystem(index_slug=self.index.slug) + self.index.rebuild() + + self.assertEqual( + list( + index_filesystem.readdir( + '/{}'.format(TEST_NODE_EXPRESSION), '' + ) + )[2:], [] + ) +