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

Fix SkipRepeatsQueue._put() raises AttributeError (#817) #818

Merged
merged 2 commits into from Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion changelog.rst
Expand Up @@ -10,7 +10,8 @@ Changelog

- [watchmedo] Fix usage of ``os.setsid()`` and ``os.killpg()`` Unix-only functions. (`#809 <https://github.com/gorakhargosh/watchdog/pull/809>`_)
- [mac] Fix missing ``FileModifiedEvent`` on permission or ownership changes of a file. (`#809 <https://github.com/gorakhargosh/watchdog/pull/814>`_)
- Thanks to our beloved contributors: @replabrobin, @BoboTiG, @SamSchott
- [mac] Fix a possible ``AttributeError`` in ``SkipRepeatsQueue._put()``. (`#818 <https://github.com/gorakhargosh/watchdog/pull/818>`_)
- Thanks to our beloved contributors: @replabrobin, @BoboTiG, @SamSchott, @AndreiB97

2.1.3
~~~~~
Expand Down
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