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

Request/Response.from_payload(...) doesn't find IDs any more #157

Closed
ghost opened this issue May 23, 2023 · 5 comments
Closed

Request/Response.from_payload(...) doesn't find IDs any more #157

ghost opened this issue May 23, 2023 · 5 comments

Comments

@ghost
Copy link

ghost commented May 23, 2023

Hi pylessard,

in the latest releases (1.17 and 1.17.1), the from_payload(...) function from Request and Response does not seem to resolve CAN-IDs any more.
The cause seems to be, that BaseService.__get_all_subclasses(cls) in BaseService.from_request_id(cls, given_id) seems to return an empty array.

I have attached a minimal working example, which works correctly in 1.16, but not in 1.17 and 1.17.1.

from udsoncan import Request, Response

def _extract_service_id_name(
    uds_payload = None
):
    if uds_payload is None:
        return None
    try:
        try:
            uds = Request.from_payload(uds_payload)
            service_id_string = f"{uds.service.__name__}"
        except AttributeError:
            uds = Response.from_payload(uds_payload)
            service_id_string = f"{uds.service.__name__ }: {uds.code_name}"
    except AttributeError:
        service_id_string = None
    return service_id_string

if __name__ == "__main__":
    extracted_service_id_name = _extract_service_id_name(bytearray([0x10, 0x02]))
    print(f"Service-ID-name: {extracted_service_id_name}")
    extracted_service_id_name = _extract_service_id_name(bytearray([0x50, 0x02]))
    print(f"Service-ID-name: {extracted_service_id_name}")

Is this an issue, or do i have to change something on my side for 1.17+?

I hope you have a nice day,
Daniel

@pylessard
Copy link
Owner

You are right. I see the error.
I have moved BaseService out of the service folder because of a circular dependency problem.
__get_all_subclasses will work only if the service module is loaded.

Of course, when the unit test runs, this module gets loaded before the test_response ad the test_request test suite.

Will fix

@pylessard
Copy link
Owner

As a workaround, you can replace your first line by from udsoncan import Request, Response, services

@ghost
Copy link
Author

ghost commented May 25, 2023

Thanks for the fast reply and resolution.
I approved your pr, as your change fixes the problem on my side :)
Thanks for the workaround code, but I already excluded 1.17.0 and 1.17.1 from my pipeline.
No problem from my side to stay at 1.16 until 1.17.2 or 1.18 goes live :)

@pylessard
Copy link
Owner

Fixed in v1.17.2
Cheers

@ghost
Copy link
Author

ghost commented May 30, 2023

Thanks a lot for the fast fix :)

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

1 participant