Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with next() and prev() when localised documents are present #1201

Open
lgiordani opened this issue Apr 19, 2022 · 1 comment · May be fixed by #1205
Open

Bug with next() and prev() when localised documents are present #1201

lgiordani opened this issue Apr 19, 2022 · 1 comment · May be fixed by #1205

Comments

@lgiordani
Copy link
Contributor

I was working on the methods next() and prev() and I found an issue when localised documents are present (like in the test suite). Add this test to documents/document_test.py

    def test_next_document_last(self):
        doc = self.pod.get_doc('/content/pages/contact.yaml', locale="de")
        expected_next_doc = None
        next_doc = doc.next()
        
        self.assertEqual(next_doc, expected_next_doc)

to expose it. The problem is that Document objects do not compare the locale in __eq__, so when the list of documents is scanned to find the current document at https://github.com/grow/grow/blob/main/grow/documents/document.py#L579 the returned document is the first of the localised, and the next is the next of the localised. In the testing suite, contact.yaml is localised in order in it, fr, and de, and the test always finds the it version, whose next() is the fr one.

Aside from the bug, I'm not sure what it the design choice here: shall next() be the next document in the collection including localisations or not?

@lgiordani
Copy link
Contributor Author

Further investigation makes me question how document comparison is handled. All comparison methods on Document (e.g. __ge__, __gt__, and so on) compare the tuple (self.pod_path, str(self.locale)), leading me to think that two documents are the same only if they have the same tuple of values. But __eq__ compares only the root_pod_path, ignoring the locale.

However, in the testing suite, we have

    def test_ge(self):
[...]
        doc1 = self.pod.get_doc('/content/pages/bravo.yaml', locale='fr')
        doc2 = self.pod.get_doc('/content/pages/bravo.yaml', locale='de')
        self.assertTrue(doc1 >= doc2)
[...]

and

    def test_gt(self):
[...]
        doc1 = self.pod.get_doc('/content/pages/bravo.yaml', locale='fr')
        doc2 = self.pod.get_doc('/content/pages/bravo.yaml', locale='de')
        self.assertTrue(doc1 > doc2)
[...]

If two things (bravo.yaml with locale fr and with locale de) are both >= and > they are different.

In conclusion, I think we should drop equality between documents with different locale.

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant