threefoldtecharchive / jumpscaleX_core

Apache License 2.0
1 stars 6 forks source link

comparing str to an enum doesn't work properly #429

Closed xmonader closed 4 years ago

xmonader commented 4 years ago

image

this was required to fix the comparison, but this means it might be broken in other code

https://github.com/threefoldtech/jumpscaleX_threebot/blob/489ce1ec0ab36a1f3e24835559ef0d0bb4266694/ThreeBotPackages/zerobot/packagemanager/actors/package_manager.py#L181

andrewayoub commented 4 years ago

Enums currently are being compared by their value which can differ in different schemas depending on the order in the options list.

in the mentioned case the enum definition in the package schema is

status = "init,config,toinstall,installed,tostart,disabled,error" (E)

and in schema_in for the actor

status = "all,init,config,toinstall,installed,tostart,disabled,error" (E)

notice that a new option (all) added in the schema in so for example the value for "init" is (1) in the first schema and (2) in the other one

Suggested solution

in __eq__ method in Enum objects we can compare by the string representation of the enum instead of the value image

is this an acceptable solution ?

despiegk commented 4 years ago

yes, string comparison ok

andrewayoub commented 4 years ago

fixed and added tests for enums here https://github.com/threefoldtech/jumpscaleX_core/blob/c9cd338fb111674c9aba97b078f58bd8ebc266c9/JumpscaleCore/data/schema/tests/13_enums.py

code: https://github.com/threefoldtech/jumpscaleX_core/commit/c9cd338fb111674c9aba97b078f58bd8ebc266c9

Dinaamagdy commented 4 years ago

verified on development run the enums tests and worked successfully image