Skip to content

fix: create a copy of appliance_data when initializing an Appliance#30

Merged
kubasaw merged 1 commit intoIoTLabs-pl:masterfrom
ramundomario:fix/issue-21-copy-appliance-data-to-avoid-changes
Feb 13, 2025
Merged

fix: create a copy of appliance_data when initializing an Appliance#30
kubasaw merged 1 commit intoIoTLabs-pl:masterfrom
ramundomario:fix/issue-21-copy-appliance-data-to-avoid-changes

Conversation

@ramundomario
Copy link

This pull request includes a change to the create_from_data method in the python/appliances/_base.py file to ensure that the appliance_data dictionary is copied before being passed to the target_cls constructor. This prevents potential side effects from modifying the original appliance_data dictionary.

Indeed this is happening with devices with multiple zones: an error will occur when creating the second appliance (zone 1) since the appliance_data is changes inside the Appliance class and the format will be changed (

appliance_data["attributes"] = {
v["parName"]: v["parValue"] for v in attributes
}
)

See IoTLabs-pl/hon#21 (comment)

  • python/appliances/_base.py: Modified create_from_data method to use appliance_data.copy() when creating appliance instances to avoid side effects.

Otherwise, on devices with multiple zones an error will occur when creating the second appliance (zone 1) since the `appliance_data` is changes inside the `Appliance` class and the format will be changed (https://github.com/IoTLabs-pl/pyhOn/blob/b869d137fddb865803efbcf9e9e940dd3c2a32f5/pyhon/appliances/_base.py#L54-L56)

See IoTLabs-pl/hon#21 (comment)
@ramundomario ramundomario marked this pull request as ready for review February 11, 2025 23:50
@kubasaw kubasaw merged commit 3ae481f into IoTLabs-pl:master Feb 13, 2025
3 checks passed
@ramundomario ramundomario deleted the fix/issue-21-copy-appliance-data-to-avoid-changes branch February 13, 2025 19:49
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