Skip to content

Commit

Permalink
fix: Address breaking change in Python 3.11 for Enums with str mixi…
Browse files Browse the repository at this point in the history
…ns (#1885)

* Update requirements.txt

* Update blackout.py

* Update enums.py

* Update heartbeat.py

* Update key.py

* Update user.py

---------

Co-authored-by: Nick Satterly <nfsatterly@gmail.com>
  • Loading branch information
alvanson and satterly committed Dec 21, 2023
1 parent 124d492 commit bdce8d6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions alerta/models/blackout.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from datetime import datetime, timedelta
from enum import Enum
from typing import Any, Dict, List, Optional, Tuple, Union
from uuid import uuid4

from flask import current_app
from strenum import StrEnum

from alerta.app import db
from alerta.database.base import Query
Expand All @@ -13,7 +13,7 @@
JSON = Dict[str, Any]


class BlackoutStatus(str, Enum):
class BlackoutStatus(StrEnum):

Pending = 'pending'
Active = 'active'
Expand Down
15 changes: 8 additions & 7 deletions alerta/models/enums.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import re
from enum import Enum

from strenum import StrEnum

class Severity(str, Enum):

class Severity(StrEnum):

Security = 'security'
Critical = 'critical'
Expand All @@ -19,7 +20,7 @@ class Severity(str, Enum):
Unknown = 'unknown'


class Status(str, Enum):
class Status(StrEnum):

Open = 'open'
Assign = 'assign'
Expand All @@ -32,7 +33,7 @@ class Status(str, Enum):
Not_Valid = 'notValid'


class Action(str, Enum):
class Action(StrEnum):

OPEN = 'open'
ASSIGN = 'assign'
Expand All @@ -45,7 +46,7 @@ class Action(str, Enum):
TIMEOUT = 'timeout'


class TrendIndication(str, Enum):
class TrendIndication(StrEnum):

More_Severe = 'moreSevere'
No_Change = 'noChange'
Expand Down Expand Up @@ -143,7 +144,7 @@ def from_str(action: str, resource: str = None, type: str = None):
ADMIN_SCOPES = [Scope.admin, Scope.read, Scope.write]


class ChangeType(str, Enum):
class ChangeType(StrEnum):

open = 'open'
assign = 'assign'
Expand All @@ -164,7 +165,7 @@ class ChangeType(str, Enum):
expired = 'expired'


class NoteType(str, Enum):
class NoteType(StrEnum):

alert = 'alert'
blackout = 'blackout'
Expand Down
4 changes: 2 additions & 2 deletions alerta/models/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import platform
import sys
from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional, Tuple, Union
from uuid import uuid4

from flask import current_app
from strenum import StrEnum

from alerta.app import db
from alerta.database.base import Query
Expand All @@ -16,7 +16,7 @@
JSON = Dict[str, Any]


class HeartbeatStatus(str, Enum):
class HeartbeatStatus(StrEnum):

OK = 'ok'
Slow = 'slow'
Expand Down
5 changes: 3 additions & 2 deletions alerta/models/key.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from datetime import datetime, timedelta
from enum import Enum
from typing import Any, Dict, List, Optional, Tuple, Union
from uuid import uuid4

from strenum import StrEnum

from alerta.app import db, key_helper
from alerta.database.base import Query
from alerta.models.enums import Scope
Expand All @@ -12,7 +13,7 @@
JSON = Dict[str, Any]


class ApiKeyStatus(str, Enum):
class ApiKeyStatus(StrEnum):

Active = 'active'
Expired = 'expired'
Expand Down
4 changes: 2 additions & 2 deletions alerta/models/user.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional, Tuple, Union
from uuid import uuid4

from flask import current_app
from strenum import StrEnum

from alerta.app import db
from alerta.auth import utils
Expand All @@ -14,7 +14,7 @@
JSON = Dict[str, Any]


class UserStatus(str, Enum):
class UserStatus(StrEnum):

Active = 'active'
Inactive = 'inactive'
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ pytz==2023.3
PyYAML==6.0
requests==2.31.0
requests_hawk==1.2.1
StrEnum==0.4.15
sentry-sdk[flask]==1.26.0
werkzeug==2.3.8

0 comments on commit bdce8d6

Please sign in to comment.