Mirror of https://github.com/roostorg/osprey github.com/roostorg/osprey
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Bug] Fix label expiry checks on reasons (#149)

authored by

jeffhalmich and committed by
GitHub
5fa8365b dcdbba0b

+12 -11
+2 -11
osprey_worker/src/osprey/engine/stdlib/udfs/labels.py
··· 214 214 215 215 if label_state is not None: 216 216 # Check to see if all reasons have expired, if so, the label should be considered as expired. 217 - # Only consider a reason expired if it has a meaningful expires_at timestamp (not default/epoch) 218 217 all_reasons_expired = all( 219 - reason.expires_at 220 - and reason.expires_at.second > 0 # Check if timestamp is not default/epoch 221 - and reason.expires_at <= now 222 - for reason in label_state.reasons.values() 218 + reason.expires_at is not None and reason.expires_at <= now for reason in label_state.reasons.values() 223 219 ) 224 220 if all_reasons_expired: 225 221 label_state = None ··· 247 243 oldest_non_expired = min( 248 244 reason.created_at 249 245 for reason in label_state.reasons.values() 250 - if reason.created_at 251 - and ( 252 - not reason.expires_at 253 - or reason.expires_at.second == 0 # No meaningful expiration set 254 - or reason.expires_at > now 255 - ) 246 + if reason.created_at and (reason.expires_at is None or reason.expires_at > now) 256 247 ) 257 248 actual_delay = now - oldest_non_expired 258 249
+10
osprey_worker/src/osprey/engine/stdlib/udfs/tests/test_labels.py
··· 133 133 LabelReasons({'ExpiringReason': LabelReason(expires_at=(datetime.now(timezone.utc) + timedelta(hours=1)))}), 134 134 True, 135 135 ), 136 + # Regression: expired reason where expires_at has second=0 should still be treated as expired 137 + ( 138 + 'added', 139 + None, 140 + LabelStatus.ADDED, 141 + LabelReasons( 142 + {'ExpiredReason': LabelReason(expires_at=datetime(2020, 1, 1, 12, 30, 0, tzinfo=timezone.utc))} 143 + ), 144 + False, 145 + ), 136 146 ('added', None, LabelStatus.MANUALLY_ADDED, LabelReasons({'TestReason': LabelReason()}), True), 137 147 ('added', None, LabelStatus.REMOVED, LabelReasons({'TestReason': LabelReason()}), False), 138 148 ('added', None, LabelStatus.MANUALLY_REMOVED, LabelReasons({'TestReason': LabelReason()}), False),