Skip to content

Commit

Permalink
Merge #456
Browse files Browse the repository at this point in the history
456: Fix RubricCollector.clear_doc() r=tshepang a=mattheww

I've seen occasional errors like the following on incremental builds:

````
Extension error (ferrocene_spec.items_with_rubric):
Handler <bound method RubricCollector.clear_doc of <ferrocene_spec.items_with_rubric.RubricCollector object at 0x7f4a44a47e50>> for event 'env-purge-doc' threw an exception (exception: pop index out of range)
````

The following code in `exts/ferrocene_spec/items_with_rubric.py`

````
    # This makes a copy of the list (with `list(items)`) to be able to
    # remove items from it without affecting the iteration.
    for i, item in enumerate(list(items)):
        if item.document == docname:
            items.pop(i)
````

won't work as intended if it finds more than one item to remove, because the first `pop` will change the positions of the following elements of the list.




Co-authored-by: Matthew Woodcraft <[email protected]>
  • Loading branch information
bors-ferrocene[bot] and mattheww authored Oct 31, 2023
2 parents 26cdabb + 7d84415 commit 496ef38
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions exts/ferrocene_spec/items_with_rubric.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ class RubricCollector(EnvironmentCollector):
def clear_doc(self, app, env, docname):
storage = get_storage(env)
for rubric, items in storage.items():
# This makes a copy of the list (with `list(items)`) to be able to
# remove items from it without affecting the iteration.
for i, item in enumerate(list(items)):
if item.document == docname:
items.pop(i)
items[:] = (item for item in items if item.document != docname)

def merge_other(self, app, env, docnames, other):
current = get_storage(env)
Expand Down

0 comments on commit 496ef38

Please sign in to comment.