diff --git a/changelog.rst b/changelog.rst index 776d8bf9..5e7ea215 100644 --- a/changelog.rst +++ b/changelog.rst @@ -10,7 +10,8 @@ Changelog - [watchmedo] Fix usage of ``os.setsid()`` and ``os.killpg()`` Unix-only functions. (`#809 `_) - [mac] Fix missing ``FileModifiedEvent`` on permission or ownership changes of a file. (`#809 `_) -- Thanks to our beloved contributors: @replabrobin, @BoboTiG, @SamSchott +- [mac] Fix a possible ``AttributeError`` in ``SkipRepeatsQueue._put()``. (`#818 `_) +- Thanks to our beloved contributors: @replabrobin, @BoboTiG, @SamSchott, @AndreiB97 2.1.3 ~~~~~ diff --git a/src/watchdog/utils/bricks.py b/src/watchdog/utils/bricks.py index 35426b7c..0a7e1cd3 100644 --- a/src/watchdog/utils/bricks.py +++ b/src/watchdog/utils/bricks.py @@ -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: diff --git a/tests/test_skip_repeats_queue.py b/tests/test_skip_repeats_queue.py index be03a801..9954a4a5 100644 --- a/tests/test_skip_repeats_queue.py +++ b/tests/test_skip_repeats_queue.py @@ -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 @@ -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()