Skip to content

fix attribute error in SdOptionCommon #35

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flolucut
Copy link

This fixes a bug, that whenever a SdOptionCommon object is called, the attribute "type" can be used.

This fixes a bug, that whenever a SdOptionCommon object is called, the attribute "type" can be used.
@chrizog
Copy link
Owner

chrizog commented Dec 20, 2024

Hi, thanks for your contribution. Can you please describe which bug exactly is fixed? When does it happen and why? From the changes in the files I can only see another way to get the type, but not a bug yet. Thanks!

@flolucut
Copy link
Author

flolucut commented Dec 21, 2024

Yes, of course.
Here are my findings:
Whenever a SdOptionCommon object is called, with the previous implementation I would get the error "AttributeError" and thus, not receiving any Offers, that are not of type SdIPV4EndpointOption:

Exception in callback _SelectorDatagramTransport._read_ready()
handle: <Handle _SelectorDatagramTransport._read_ready()>
Traceback (most recent call last):
File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "/usr/lib/python3.8/asyncio/selector_events.py", line 1021, in _read_ready
self._protocol.datagram_received(data, addr)
File "/home/developer/.local/lib/python3.8/site-packages/someipy/_internal/utils.py", line 104, in datagram_received
self.target.datagram_received(data, addr)
File "/home/developer/.local/lib/python3.8/site-packages/someipy/service_discovery.py", line 147, in datagram_received
for offered_service in extract_offered_services(someip_sd_header):
File "/home/developer/.local/lib/python3.8/site-packages/someipy/_internal/someip_sd_extractors.py", line 55, in extract_offered_services
if option.sd_option_common.type == SdOptionType.IPV4_ENDPOINT:
AttributeError: 'SdOptionCommon' object has no attribute 'sd_option_common'

The if-statement only works for classes of type SdIPV4EndpointOption, because it is the only class that has an attribute "sd_option_common".
With the solution I provided, the call of the exact SdOptionType is hidden behind an interface. This ensures that you would get the correct SdOptionType for SdOptionCommon and SdIPV4EndpointOption (and also every other class that is derived from SdOptionInterface), not having to deal with the exact attributes of each class.

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.

2 participants