Skip to content

Commit

Permalink
Fix SkipRepeatsQueue._put() raises AttributeError (#817)
Browse files Browse the repository at this point in the history
This fixes an issue with SkipRepeatsQueue._put() which causes it to raise
an AttributeError on the first put. This is done by adding a check to test
if _last_item is set to None, which is the value set by __init__()
  • Loading branch information
AndreiB97 committed Jul 18, 2021
1 parent 1be65c0 commit ec2bfd9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/watchdog/utils/bricks.py
Expand Up @@ -87,7 +87,7 @@ def _init(self, maxsize):
self._last_item = None

def _put(self, item):
if item != self._last_item:
if self._last_item is None or item != self._last_item:
super()._put(item)
self._last_item = item
else:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_skip_repeats_queue.py
Expand Up @@ -16,6 +16,7 @@
# limitations under the License.

import pytest
import watchdog.events as events
from watchdog.utils.bricks import SkipRepeatsQueue

from .markers import cpython_only
Expand Down Expand Up @@ -58,6 +59,18 @@ def test_allow_nonconsecutive():
assert q.empty()


def test_put_with_watchdog_events():
# FileSystemEvent.__ne__() uses the key property without
# doing any type checking. Since _last_item is set to
# None in __init__(), an AttributeError is raised when
# FileSystemEvent.__ne__() tries to use None.key
queue = SkipRepeatsQueue()
dummy_file = 'dummy.txt'
event = events.FileCreatedEvent(dummy_file)
queue.put(event)
assert queue.get() is event


def test_prevent_consecutive():
q = SkipRepeatsQueue()

Expand Down

0 comments on commit ec2bfd9

Please sign in to comment.