Skip to content

Commit 3efc288

Browse files
committed
fix(models_utils): paginated data now also receives status code when instantiated from 'from_response'
1 parent b87bc42 commit 3efc288

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

pygitguardian/models.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Base,
2929
BaseSchema,
3030
FromDictMixin,
31+
FromDictWithBase,
3132
PaginationParameter,
3233
SearchParameter,
3334
ToDictMixin,
@@ -113,7 +114,7 @@ def make_detail_response(self, data: Dict[str, Any], **kwargs: Any) -> "Detail":
113114
return Detail(**data)
114115

115116

116-
class Detail(Base, FromDictMixin):
117+
class Detail(FromDictWithBase):
117118
"""Detail is a response object mostly returned on error or when the
118119
api output is a simple string.
119120
@@ -146,7 +147,7 @@ def make_match(self, data: Dict[str, Any], **kwargs: Any) -> "Match":
146147
return Match(**data)
147148

148149

149-
class Match(Base, FromDictMixin):
150+
class Match(FromDictWithBase):
150151
"""
151152
Match describes an issue found by GitGuardian.
152153
@@ -231,7 +232,7 @@ def make_policy_break(self, data: Dict[str, Any], **kwargs: Any) -> "PolicyBreak
231232
return PolicyBreak(**data)
232233

233234

234-
class PolicyBreak(Base, FromDictMixin):
235+
class PolicyBreak(FromDictWithBase):
235236
"""
236237
PolicyBreak describes a GitGuardian policy break found
237238
in a scan.
@@ -288,7 +289,7 @@ def make_scan_result(self, data: Dict[str, Any], **kwargs: Any) -> "ScanResult":
288289
return ScanResult(**data)
289290

290291

291-
class ScanResult(Base, FromDictMixin):
292+
class ScanResult(FromDictWithBase):
292293
"""ScanResult is a response object returned on a Content Scan
293294
294295
Attributes:
@@ -378,7 +379,7 @@ def make_scan_result(
378379
return MultiScanResult(**data)
379380

380381

381-
class MultiScanResult(Base, FromDictMixin):
382+
class MultiScanResult(FromDictWithBase):
382383
"""ScanResult is a response object returned on a Content Scan
383384
384385
Attributes:
@@ -956,7 +957,7 @@ class Scan(Base, FromDictMixin):
956957

957958

958959
@dataclass
959-
class Source(Base, FromDictMixin):
960+
class Source(FromDictWithBase):
960961
id: int
961962
url: str
962963
type: str
@@ -1110,7 +1111,7 @@ def make_members_parameters(self, data: Dict[str, Any], **kwargs: Any):
11101111

11111112

11121113
@dataclass
1113-
class Member(Base, FromDictMixin):
1114+
class Member(FromDictWithBase):
11141115
"""
11151116
Member represents a user in a GitGuardian account.
11161117
"""
@@ -1168,7 +1169,7 @@ def access_level_value(self, data: Dict[str, Any], **kwargs: Any) -> Dict[str, A
11681169

11691170

11701171
@dataclass
1171-
class UpdateMember(Base, FromDictMixin):
1172+
class UpdateMember(FromDictWithBase):
11721173
"""
11731174
UpdateMember represents the payload to update a member
11741175
"""
@@ -1182,7 +1183,7 @@ class UpdateMember(Base, FromDictMixin):
11821183

11831184

11841185
@dataclass
1185-
class UpdateMemberParameters(Base, FromDictMixin):
1186+
class UpdateMemberParameters(FromDictWithBase):
11861187
send_email: Optional[bool] = None
11871188

11881189

@@ -1194,7 +1195,7 @@ class UpdateMemberParameters(Base, FromDictMixin):
11941195

11951196

11961197
@dataclass
1197-
class DeleteMemberParameters(Base, FromDictMixin):
1198+
class DeleteMemberParameters(FromDictWithBase):
11981199
id: int
11991200
send_email: Optional[bool] = None
12001201

@@ -1219,7 +1220,7 @@ class TeamsParameters(PaginationParameter, SearchParameter, FromDictMixin, ToDic
12191220

12201221

12211222
@dataclass
1222-
class Team(Base, FromDictMixin):
1223+
class Team(FromDictWithBase):
12231224
id: int
12241225
name: str
12251226
is_global: bool
@@ -1235,7 +1236,7 @@ class Team(Base, FromDictMixin):
12351236

12361237

12371238
@dataclass
1238-
class CreateTeam(Base, FromDictMixin):
1239+
class CreateTeam(FromDictWithBase):
12391240
name: str
12401241
description: Optional[str] = ""
12411242

@@ -1250,7 +1251,7 @@ class CreateTeam(Base, FromDictMixin):
12501251

12511252

12521253
@dataclass
1253-
class UpdateTeam(Base, FromDictMixin):
1254+
class UpdateTeam(FromDictWithBase):
12541255
id: int
12551256
name: Optional[str]
12561257
description: Optional[str] = None
@@ -1296,7 +1297,7 @@ class Meta:
12961297

12971298

12981299
@dataclass
1299-
class TeamInvitation(Base, FromDictMixin):
1300+
class TeamInvitation(FromDictWithBase):
13001301
id: int
13011302
invitation_id: int
13021303
team_id: int
@@ -1326,7 +1327,7 @@ def make_team_invitation(
13261327

13271328

13281329
@dataclass
1329-
class CreateTeamInvitation(Base, FromDictMixin):
1330+
class CreateTeamInvitation(FromDictWithBase):
13301331
invitation_id: int
13311332
is_team_leader: bool
13321333
incident_permission: IncidentPermission
@@ -1376,7 +1377,7 @@ class Meta:
13761377

13771378

13781379
@dataclass
1379-
class TeamMember(Base, FromDictMixin):
1380+
class TeamMember(FromDictWithBase):
13801381
id: int
13811382
team_id: int
13821383
member_id: int
@@ -1416,7 +1417,7 @@ class CreateTeamMemberParameters(ToDictMixin):
14161417

14171418

14181419
@dataclass
1419-
class CreateTeamMember(Base, FromDictMixin):
1420+
class CreateTeamMember(FromDictWithBase):
14201421
member_id: int
14211422
is_team_leader: bool
14221423
incident_permission: IncidentPermission
@@ -1456,7 +1457,7 @@ class TeamSourceParameters(PaginationParameter, SearchParameter, ToDictMixin):
14561457

14571458

14581459
@dataclass
1459-
class UpdateTeamSource(Base, FromDictMixin):
1460+
class UpdateTeamSource(FromDictWithBase):
14601461
team_id: int
14611462
sources_to_add: List[int]
14621463
sources_to_remove: List[int]
@@ -1490,7 +1491,7 @@ class InvitationParameters(
14901491

14911492

14921493
@dataclass
1493-
class Invitation(Base, FromDictMixin):
1494+
class Invitation(FromDictWithBase):
14941495
id: int
14951496
email: str
14961497
access_level: AccessLevel

pygitguardian/models_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ class SearchParameter(ToDictMixin):
9090
search: Optional[str] = None
9191

9292

93-
PaginatedData = TypeVar("PaginatedData", bound=FromDictMixin)
93+
class FromDictWithBase(FromDictMixin, Base):
94+
pass
95+
96+
97+
PaginatedData = TypeVar("PaginatedData", bound=FromDictWithBase)
9498

9599

96100
@dataclass
@@ -107,6 +111,9 @@ def from_response(
107111
data = cast(
108112
List[PaginatedData], [data_type.from_dict(obj) for obj in response.json()]
109113
)
114+
for element in data:
115+
element.status_code = response.status_code
116+
110117
paginated_response = cls(status_code=response.status_code, data=data)
111118

112119
if previous_page := response.links.get("prev"):

0 commit comments

Comments
 (0)