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

Problem with iteration over queue in .indexing.IndexQueue.process #79

Open
jensens opened this issue Jul 12, 2019 · 3 comments
Open

Problem with iteration over queue in .indexing.IndexQueue.process #79

jensens opened this issue Jul 12, 2019 · 3 comments

Comments

@jensens
Copy link
Member

jensens commented Jul 12, 2019

I wrote an multilingual fallback index for Plone plone.app.multilingualindexes. In order to get all items up to date, I need to cross-index objects. On unindex_object I need to reindex the same index of all objects in the same translation group. When doing so, for some reason (I did not figured out why) the for loop is reset:

for op, obj, attributes, metadata in self.queue:

I have two items in the queue and the first item is processed twice (and then unindex fails).
I took the debugger and stepped through to verify this.

No idea how. I guess the iterator of self.queue was reset while unindex runs.

I then tried to work around the iterator reset - which results in this code:

    while self.queue:
        op, obj, attributes, metadata = self.queue.pop(0)

see https://github.com/plone/plone.app.multilingualindexes/blob/e89cc65db76108d7050ef73b6171987fd2ba0d41/src/plone/app/multilingualindexes/patches.py#L18-L19

And now all works fine.

I would really like to provide a pull request, but I first I want to understand what happens here. Also, I have no good idea how to write a test for this effect.

Is anyone here with more insights/ ideas?

@d-maurer
Copy link
Contributor

d-maurer commented Jul 13, 2019 via email

@jensens
Copy link
Member Author

jensens commented Jul 13, 2019

Thus, if you perform a catalog search

Probably that is the problem. In order to get the other translations I use the Translation Manager which queries the catalog.

I would implement a recursive call detection in IndexQueue.process
to check whether process is called recursively in your case

Idea: Set a flag on the queue if a "process" is at work, unset if done.
If flag is set, skip subsequent processing.
Opinions?

@d-maurer
Copy link
Contributor

d-maurer commented Jul 13, 2019 via email

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

No branches or pull requests

2 participants