Skip to content

driver: don't assume target is set in __str__ - #1942

Open
Sanjays2402 wants to merge 1 commit into
labgrid-project:masterfrom
Sanjays2402:fix/driver-str-unbound-target
Open

driver: don't assume target is set in __str__#1942
Sanjays2402 wants to merge 1 commit into
labgrid-project:masterfrom
Sanjays2402:fix/driver-str-unbound-target

Conversation

@Sanjays2402

Copy link
Copy Markdown

Description

Driver.__attrs_post_init__ temporarily sets self.target = None while binding is in progress, so a driver's __str__ must not dereference it. When Target.bind_driver raised BindingError(f"{client} got unexpected bindings: ..."), formatting that message called SerialDriver.__str__ and blew up with AttributeError: 'NoneType' object has no attribute 'name', hiding the real cause. QemuDriver.__str__ had the same pattern, so both were fixed (as suggested in the issue).

Tested locally: the new test_unexpected_binding_reports_binding_error fails with the reported AttributeError without the source change and passes with it; tests/test_serialdriver.py and tests/test_target.py are green (52 passed).

Checklist

  • Documentation for the feature
  • Tests for the feature
  • The arguments and description in doc/configuration.rst have been updated
  • Add a section on how to use the feature to doc/usage.rst
  • Add a section on how to use the feature to doc/development.rst
  • PR has been tested
  • Man pages have been regenerated

Fixes #1414

Driver.__attrs_post_init__ temporarily clears self.target while binding
is in progress, so a driver's __str__ must not dereference it. When
bind_driver raised a BindingError for unexpected bindings, formatting
the message called SerialDriver.__str__ and failed with
"AttributeError: 'NoneType' object has no attribute 'name'", hiding the
real cause. QemuDriver had the same pattern.

Fixes labgrid-project#1414
@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.0%. Comparing base (ebe3535) to head (baff58b).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/driver/qemudriver.py 0.0% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1942     +/-   ##
========================================
- Coverage    61.0%   61.0%   -0.1%     
========================================
  Files         182     182             
  Lines       14881   14883      +2     
========================================
- Hits         9086    9082      -4     
- Misses       5795    5801      +6     
Flag Coverage Δ
3.10 61.0% <50.0%> (-0.1%) ⬇️
3.11 61.0% <50.0%> (-0.1%) ⬇️
3.12 61.0% <50.0%> (-0.1%) ⬇️
3.13 60.9% <50.0%> (-0.1%) ⬇️
3.14 60.9% <50.0%> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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.

SerialDriver: BindingErrors hidden by AttributeError caused by not (yet) set target

1 participant