temporalio / sdk-python

Temporal Python SDK
MIT License
472 stars 75 forks source link

[Bug] `ScheduleOverlapPolicy` has broken __eq__ #652

Open andersio opened 2 months ago

andersio commented 2 months ago

What are you really trying to do?

In a deployment script, compare a Schedule on the server to a proposed Schedule, and skip schedule updates as needed.

Describe the bug

When comparing two Schedules that differ only in their ScheduleOverlapPolicy, Schedule.__eq__ returns true.

This seems to be caused by ScheduleOverlapPolicy, where every enum case apparently equals to any cases according to ScheduleOverlapPolicy.__eq__, even though the underlying values are different.

For some reason, ScheduleOverlapPolicy is both a dataclass and an IntEnum. Seems like the rare combination might have caused the behaviour here?

Minimal Reproduction

from temporalio.client import ScheduleOverlapPolicy

print(ScheduleOverlapPolicy.SKIP == ScheduleOverlapPolicy.TERMINATE_OTHER)
# console: True

print(int(ScheduleOverlapPolicy.SKIP) == int(ScheduleOverlapPolicy.TERMINATE_OTHER))
# console: False

print(ScheduleOverlapPolicy.SKIP.value == ScheduleOverlapPolicy.TERMINATE_OTHER.value)
# console: False

Environment/Versions

Python 3.11.7

 name         : temporalio             
 version      : 1.7.0                  
 description  : Temporal.io Python SDK 

dependencies
 - protobuf >=3.20
 - types-protobuf >=3.20
 - typing-extensions >=4.2.0,<5.0.0

Additional context

cretz commented 2 months ago

For some reason, ScheduleOverlapPolicy is both a dataclass and an IntEnum

This was a mistake on our part and was fixed in #628 and therefore the fix is in 1.7.1. Can you confirm?