Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Avoid truncating unknown types in SDO upload (fixes #436) #591

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

Merged

Conversation

acolomb
Copy link
Member

@acolomb acolomb commented Jun 15, 2025

When an OD entry is found in SdoClient.upload(), the truncation is currently skipped only for those types explicitly listed as variable length data (domain, strings). That causes unknown types to be truncated to whatever their length indicates, which is usually one byte.

Invert the condition to check all types with an explicitly known size, a.k.a. those listed in STRUCT_TYPES where the required length can be deduced from the structure format. Factor out the condition to a new fixed_size property, which is easier to override when adding custom data types.

Re-enable the unit tests which were skipped based on the previously buggy behavior.

When an OD entry is found in SdoClient.upload(), the truncation is
currently skipped only for those types explicitly listed as variable
length data (domain, strings).  That causes unknown types to be
truncated to whatever their length indicates, which is usually one
byte.

Invert the condition to check all types with an explicitly known size,
a.k.a. those listed in STRUCT_TYPES where the required length can be
deduced from the structure format.

Re-enable the unit tests which were skipped based on the previously
buggy behavior.
Copy link

codecov bot commented Jun 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@sveinse
Copy link
Collaborator

sveinse commented Jun 15, 2025

This is an efficient fix.

@acolomb
Copy link
Member Author

acolomb commented Jun 15, 2025

Does that mean PR approval?

Copy link
Collaborator

@sveinse sveinse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean PR approval?

If our goal is to keep the design as close to as-is, this I think is the minimal efforts to fulfil #436. And it has the minimal impact on the existing code base. Approved.👌

@acolomb acolomb merged commit 7fb914a into canopen-python:master Jun 15, 2025
4 of 5 checks passed
@acolomb acolomb deleted the sdo-truncate-only-known-length branch June 15, 2025 18:26
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