driver: don't assume target is set in __str__ - #1942
Open
Sanjays2402 wants to merge 1 commit into
Open
Conversation
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Driver.__attrs_post_init__temporarily setsself.target = Nonewhile binding is in progress, so a driver's__str__must not dereference it. WhenTarget.bind_driverraisedBindingError(f"{client} got unexpected bindings: ..."), formatting that message calledSerialDriver.__str__and blew up withAttributeError: '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_errorfails with the reportedAttributeErrorwithout the source change and passes with it;tests/test_serialdriver.pyandtests/test_target.pyare green (52 passed).Checklist
Fixes #1414