Skip to content

fix(client): raise AttributeError, not KeyError, for missing dunders#290

Draft
bluetoothbot wants to merge 1 commit into
openvideolibs:asyncfrom
bluetoothbot:koan/getattr-raises-attributeerror
Draft

fix(client): raise AttributeError, not KeyError, for missing dunders#290
bluetoothbot wants to merge 1 commit into
openvideolibs:asyncfrom
bluetoothbot:koan/getattr-raises-attributeerror

Conversation

@bluetoothbot

@bluetoothbot bluetoothbot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What: ONVIFService.__getattr__ now raises AttributeError for missing dunders instead of KeyError.

Why: __getattr__ only runs after normal attribute lookup fails, so the old return self.__dict__[name] always raised KeyError. Python's data model requires AttributeError here — a KeyError escapes hasattr() and the 3-arg getattr(obj, name, default) fallback (both only suppress AttributeError), and it breaks copy.deepcopy(), which probes __deepcopy__ on the instance:

copy.deepcopy(service)                 # KeyError -> AttributeError (now works)
hasattr(service, "__deepcopy__")       # KeyError -> False
getattr(service, "__deepcopy__", None) # KeyError -> None

How: Replaced return self.__dict__[name] with raise AttributeError(name), keeping the original intent (don't proxy dunder access to the ONVIF operation dispatcher). Updated the test that pinned the old KeyError behavior and added coverage for the stdlib protocols above.

Testing: pytest (256 passed), ruff check clean.


Quality Report

Changes: 87 files changed, 9581 insertions(+), 1475 deletions(-)

Code scan: 20 issue(s) found

  • README.rst:61 — debug print statement
  • README.rst:111 — debug print statement
  • examples/events.py:20 — debug print statement
  • examples/events.py:24 — debug print statement
  • examples/events.py:25 — debug print statement
  • examples/events.py:27 — debug print statement
  • examples/events.py:29 — debug print statement
  • examples/events.py:62 — debug print statement
  • examples/events.py:74 — debug print statement
  • examples/events.py:84 — debug print statement

Tests: failed (FAILED)

Branch hygiene: clean

Generated by Kōan

ONVIFService.__getattr__ returned self.__dict__[name] for any unset dunder,
which raises KeyError. __getattr__ only fires after normal lookup fails, so
this always raised KeyError instead of the AttributeError the Python data
model requires. The KeyError leaked out of hasattr() and the 3-arg getattr()
fallback, and broke copy.deepcopy(), which probes __deepcopy__ on the instance.

Raise AttributeError(name) instead. Update the test that pinned the old
KeyError behavior and add coverage proving hasattr/getattr-default/deepcopy
now behave transparently.
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
onvif/client.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Successfully merging this pull request may close these issues.

1 participant