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

AttributeError: 'NoneType' object has no attribute 'key' #817

Closed
AndreiB97 opened this issue Jul 18, 2021 · 1 comment
Closed

AttributeError: 'NoneType' object has no attribute 'key' #817

AndreiB97 opened this issue Jul 18, 2021 · 1 comment

Comments

@AndreiB97
Copy link
Contributor

The first time EventQueue.put() is executed it throws the following exception:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\Andrei\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
    self.run()
  File "D:\OneDrive\Projects\PySync\venv\lib\site-packages\watchdog\observers\api.py", line 199, in run
    self.dispatch_events(self.event_queue, self.timeout)
  File "D:\OneDrive\Projects\PySync\venv\lib\site-packages\watchdog\observers\api.py", line 372, in dispatch_events
    handler.dispatch(event)
  File "D:\OneDrive\Projects\PySync\venv\lib\site-packages\watchdog\events.py", line 403, in dispatch
    super().dispatch(event)
  File "D:\OneDrive\Projects\PySync\venv\lib\site-packages\watchdog\events.py", line 271, in dispatch
    self.on_any_event(event)
  File "D:\OneDrive\Projects\PySync\PySync\client.py", line 25, in <lambda>
    self.handler.on_any_event = lambda event: self.queue.put(event)
  File "C:\Users\Andrei\AppData\Local\Programs\Python\Python39\lib\queue.py", line 150, in put
    self._put(item)
  File "D:\OneDrive\Projects\PySync\venv\lib\site-packages\watchdog\utils\bricks.py", line 90, in _put
    if item != self._last_item:
  File "D:\OneDrive\Projects\PySync\venv\lib\site-packages\watchdog\events.py", line 158, in __ne__
    return self.key != event.key
AttributeError: 'NoneType' object has no attribute 'key'

The problem seems to be this line: https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/bricks.py#L90
In __init__ _last_item is set to None and FileSystemEvent.__ne__() uses the key property without checking the type of the other event.

This can be fixed by changing the line from:

if item != self._last_item:

to:

if self._last_item is None or item != self._last_item:

I'm currently running version 2.1.3 on Windows 10:

pip show watchdog
Name: watchdog
Version: 2.1.3
Summary: Filesystem events monitoring
Home-page: https://github.com/gorakhargosh/watchdog
Author: Yesudeep Mangalapilly
Author-email: yesudeep@gmail.com
License: Apache License 2.0
Location: c:\users\andrei\appdata\local\programs\python\python39\lib\site-packages
Requires:
Required-by:
AndreiB97 added a commit to AndreiB97/watchdog that referenced this issue Jul 18, 2021
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__()`
AndreiB97 added a commit to AndreiB97/watchdog that referenced this issue Jul 18, 2021
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__()
AndreiB97 added a commit to AndreiB97/watchdog that referenced this issue Jul 18, 2021
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__()
BoboTiG added a commit that referenced this issue Jul 28, 2021
* Fix SkipRepeatsQueue._put() raises AttributeError (#817)

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__()

* Update changelog.rst

Co-authored-by: Mickaël Schoentgen <contact@tiger-222.fr>
@BoboTiG
Copy link
Collaborator

BoboTiG commented Jul 28, 2021

Closed with #818.

@BoboTiG BoboTiG closed this as completed Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants