22
22
class MentorshipAffiliationsTable (BaseAirtableTable ):
23
23
"""Airtable table for the mentorship affiliations table."""
24
24
25
- def __init__ (self ) -> None : # noqa: ANN101, D107
25
+ def __init__ (self : "MentorshipAffiliationsTable" ) -> None :
26
+ """Initialize the mentorship affiliations table."""
26
27
super ().__init__ ("Affiliations" )
27
28
28
29
@cached_property
29
- def valid_affiliations (self ) -> list [MentorshipAffiliation ]: # noqa: ANN101
30
+ def valid_affiliations (self : "MentorshipAffiliationsTable" ) -> list [MentorshipAffiliation ]:
30
31
"""Return the valid affiliations from the table.
31
32
32
33
:return: A list of valid affiliations.
33
34
"""
34
35
return [self .parse_affiliation_row (row ) for row in self .all (view = "Valid" )]
35
36
36
37
@staticmethod
37
- def parse_affiliation_row (row : dict [str , Any ]) -> MentorshipAffiliation : # noqa: D102
38
+ def parse_affiliation_row (row : dict [str , Any ]) -> MentorshipAffiliation :
39
+ """Parse an affiliation row.
40
+
41
+ :param row: The row to parse.
42
+ :return: The parsed affiliation row.
43
+ """
38
44
fields = {snake_case (k ): v for k , v in row ["fields" ].items ()}
39
45
try :
40
46
return MentorshipAffiliation (
@@ -47,75 +53,97 @@ def parse_affiliation_row(row: dict[str, Any]) -> MentorshipAffiliation: # noqa
47
53
raise validation_exception from validation_exception
48
54
49
55
50
- class MentorshipMentorsTable (BaseAirtableTable ): # noqa: D101
51
- def __init__ (self ): # noqa: ANN101, ANN204, D107
56
+ class MentorshipMentorsTable (BaseAirtableTable ):
57
+ """Table containing the mentors who have signed up to mentor others."""
58
+
59
+ def __init__ (self : "MentorshipMentorsTable" ) -> None :
60
+ """Initialize the mentorship mentors table."""
52
61
super ().__init__ ("Mentors" )
53
62
54
63
@cached_property
55
- def valid_mentors (self ) -> list [Mentor ]: # noqa: ANN101
64
+ def valid_mentors (self : "MentorshipMentorsTable" ) -> list [Mentor ]:
56
65
"""Returns the mentors from the table sorted by row ID.
57
66
58
67
:return: list of mentors
59
- :rtype: list[Mentor]
60
68
"""
61
69
try :
62
70
return [self .parse_mentor_row (row ) for row in self .all (view = "Valid" )]
63
- except ValidationError as valid_e :
64
- raise valid_e # noqa: TRY201
71
+ except ValidationError :
72
+ logger .exception ("Unable to retrieve the list of mentors" )
73
+ raise
65
74
66
75
@staticmethod
67
- def parse_mentor_row (row : dict [str , Any ]) -> Mentor : # noqa: D102
76
+ def parse_mentor_row (row : dict [str , Any ]) -> Mentor :
77
+ """Parse a mentor row.
78
+
79
+ :param row: The row to parse.
80
+ :return: The parsed row.
81
+ """
68
82
fields = {snake_case (k ): v for k , v in row ["fields" ].items ()}
69
83
try :
70
84
return Mentor (
71
85
** fields ,
72
86
airtable_id = row ["id" ],
73
87
created_at = row ["createdTime" ],
74
88
)
75
- except ValidationError as valid_e :
76
- raise valid_e # noqa: TRY201
89
+ except ValidationError :
90
+ logger .exception ("Unable to parse mentor row." , extra = {"row" : row })
91
+ raise
77
92
78
93
79
- class MentorshipSkillsetsTable (BaseAirtableTable ): # noqa: D101
80
- def __init__ (self ): # noqa: ANN101, ANN204, D107
94
+ class MentorshipSkillsetsTable (BaseAirtableTable ):
95
+ """Airtable table for the mentorship skillsets table."""
96
+
97
+ def __init__ (self : "MentorshipSkillsetsTable" ) -> None :
98
+ """Initialize the mentorship skillsets table."""
81
99
super ().__init__ ("Skillsets" )
82
100
83
101
@cached_property
84
- def valid_skillsets (self ) -> list [MentorshipSkillset ]: # noqa: ANN101
102
+ def valid_skillsets (self : "MentorshipSkillsetsTable" ) -> list [MentorshipSkillset ]:
85
103
"""Returns the skillsets from the table.
86
104
87
- :return: list of skillsets
88
- :rtype: list[MentorshipSkillset]
105
+ :return: The list of skillsets.
89
106
"""
90
107
try :
91
108
return [self .parse_skillset_row (row ) for row in self .all (view = "Valid" )]
92
- except ValidationError as valid_e :
93
- raise valid_e # noqa: TRY201
109
+ except ValidationError :
110
+ logger .exception ("Unable to retrieve the list of skillsets" )
111
+ raise
94
112
95
113
@cached_property
96
- def mentors_by_skillsets (self ) -> dict [str , str ]: # noqa: ANN101, D102
114
+ def mentors_by_skillsets (self : "MentorshipSkillsetsTable" ) -> dict [str , str ]:
115
+ """Returns the mentors by skillset.
116
+
117
+ :return: The mentors by skillset.
118
+ """
97
119
try :
98
120
mentors_by_skillset = {}
99
121
for row in self .all (fields = ["Name" , "Mentors" ], view = "Valid" ):
100
122
mentors_by_skillset [row ["Name" ]] = row ["Mentors" ]
101
123
return mentors_by_skillset # noqa: TRY300
102
- except Exception as e :
103
- logger .warning ( f "Issue retrieving mentor IDs by skillset: { e } " ) # noqa: G004
104
- raise e # noqa: TRY201
124
+ except Exception :
125
+ logger .exception ( "Issue retrieving mentor IDs by skillset" )
126
+ raise
105
127
106
128
@staticmethod
107
- def parse_skillset_row (row : dict [str , Any ]) -> MentorshipSkillset : # noqa: D102
129
+ def parse_skillset_row (row : dict [str , Any ]) -> MentorshipSkillset :
130
+ """Parse a skillset row.
131
+
132
+ :param row: The row to parse.
133
+ :return: The parsed row.
134
+ """
108
135
fields = {snake_case (k ): v for k , v in row ["fields" ].items ()}
109
136
try :
110
137
return MentorshipSkillset (
111
138
** fields ,
112
139
airtable_id = row ["id" ],
113
140
created_at = row ["createdTime" ],
114
141
)
115
- except ValidationError as valid_e :
116
- raise valid_e # noqa: TRY201
142
+ except ValidationError :
143
+ logger .exception ("Unable to parse skillset row." , extra = {"row" : row })
144
+ raise
117
145
118
- def mentors_by_skillset (self , skillsets_to_search : list [str ]) -> set [str ]: # noqa: ANN101
146
+ def mentors_by_skillset (self : "MentorshipSkillsetsTable" , skillsets_to_search : list [str ]) -> set [str ]:
119
147
"""Retrieve mentor IDs by skillset.
120
148
121
149
:param skillsets_to_search: The skillsets to search for.
@@ -134,78 +162,106 @@ def mentors_by_skillset(self, skillsets_to_search: list[str]) -> set[str]: # no
134
162
mentors .append (
135
163
row ["fields" ]["Mentors" ] if row ["fields" ]["Mentors" ] else [],
136
164
)
137
- except KeyError as key_e :
138
- logger .warning ( f "Key error intercepted: { key_e } " ) # noqa: G004
165
+ except KeyError :
166
+ logger .exception ( "Key error intercepted retrieving mentors by skillset" , extra = { "row" : row })
139
167
pass
140
168
141
169
# Flatten the array and get unique values
142
170
return set (chain (* mentors ))
143
- except Exception as e :
171
+ except Exception :
144
172
logger .exception (
145
173
"Issue retrieving mentor IDs with particular skillsets" ,
146
- extra = {"error" : e , " skillsets" : skillsets_to_search },
174
+ extra = {"skillsets" : skillsets_to_search },
147
175
)
148
- raise e from e
176
+ raise
149
177
150
178
151
- class MentorshipServicesTable (BaseAirtableTable ): # noqa: D101
152
- def __init__ (self ): # noqa: ANN101, ANN204, D107
179
+ class MentorshipServicesTable (BaseAirtableTable ):
180
+ """Airtable table for the mentorship services table."""
181
+
182
+ def __init__ (self : "MentorshipServicesTable" ) -> None :
183
+ """Initialize the mentorship services table."""
153
184
super ().__init__ ("Services" )
154
185
155
186
@cached_property
156
- def valid_services (self ) -> list [MentorshipService ]: # noqa: ANN101
187
+ def valid_services (self : "MentorshipServicesTable" ) -> list [MentorshipService ]:
157
188
"""Returns the services from the table.
158
189
159
- :return: list of services from the table
160
- :rtype: list[MentorshipService]
190
+ :return: The list of services from the table.
161
191
"""
162
192
try :
163
193
return [self .parse_service_row (row ) for row in self .all (view = "Valid" )]
164
- except ValidationError as valid_e :
165
- raise valid_e # noqa: TRY201
194
+ except ValidationError :
195
+ logger .exception ("Unable to retrieve the list of services" )
196
+ raise
166
197
167
198
@staticmethod
168
- def parse_service_row (row : dict [str , Any ]) -> MentorshipService : # noqa: D102
199
+ def parse_service_row (row : dict [str , Any ]) -> MentorshipService :
200
+ """Parse a service row.
201
+
202
+ :param row: The row to parse.
203
+ :return: The parsed row.
204
+ """
169
205
fields = {snake_case (k ): v for k , v in row ["fields" ].items ()}
170
206
try :
171
207
return MentorshipService (
172
208
** fields ,
173
209
airtable_id = row ["id" ],
174
210
created_at = row ["createdTime" ],
175
211
)
176
- except ValidationError as valid_e :
177
- raise valid_e # noqa: TRY201
212
+ except ValidationError :
213
+ logger .exception ("Unable to parse service row." , extra = {"row" : row })
214
+ raise
215
+
178
216
217
+ class MentorshipRequestsTable (BaseAirtableTable ):
218
+ """Airtable table for the mentorship requests table."""
179
219
180
- class MentorshipRequestsTable ( BaseAirtableTable ): # noqa: D101
181
- def __init__ ( self ): # noqa: ANN101, ANN204, D107
220
+ def __init__ ( self : "MentorshipRequestsTable" ) -> None :
221
+ """Initialize the mentorship requests table."""
182
222
super ().__init__ ("Mentor Requests" )
183
223
184
224
@cached_property
185
- def valid_services (self ) -> list [MentorshipRequest ]: # noqa: ANN101
225
+ def valid_services (self : "MentorshipRequestsTable" ) -> list [MentorshipRequest ]:
186
226
"""Returns the services from the table.
187
227
188
228
:return: list of services from the table
189
- :rtype: list[MentorshipService]
190
229
"""
191
230
try :
192
231
return [self .parse_request_row (row ) for row in self .all (view = "Valid" )]
193
- except ValidationError as valid_e :
194
- raise valid_e # noqa: TRY201
232
+ except ValidationError :
233
+ logger .exception ("Unable to retrieve the list of requests" )
234
+ raise
195
235
196
236
@staticmethod
197
- def parse_request_row (row : dict [str , Any ]) -> MentorshipRequest : # noqa: D102
237
+ def parse_request_row (row : dict [str , Any ]) -> MentorshipRequest :
238
+ """Parse a request row.
239
+
240
+ :param row: The row to parse.
241
+ :return: The parsed row.
242
+ """
198
243
fields = {snake_case (k ): v for k , v in row ["fields" ].items ()}
199
244
try :
200
245
return MentorshipRequest (
201
246
** fields ,
202
247
airtable_id = row ["id" ],
203
248
created_at = row ["createdTime" ],
204
249
)
205
- except ValidationError as valid_e :
206
- raise valid_e # noqa: TRY201
250
+ except ValidationError :
251
+ logger .exception ("Unable to parse request row." , extra = {"row" : row })
252
+ raise
207
253
208
- def return_record_by_slack_message_ts (self , timestamp : str ) -> MentorshipRequest : # noqa: ANN101, D102
254
+ def return_record_by_slack_message_ts (self : "MentorshipRequestsTable" , timestamp : str ) -> MentorshipRequest :
255
+ """Return a specific record by the recorded timestamp.
256
+
257
+ :param timestamp: The timestamp to use to find the record.
258
+ :return: The mentorship request found with the timestamp.
259
+ """
260
+ logger .info ("Returning record using timestamp" , extra = {"timestamp" : timestamp })
209
261
row = self .first (formula = f"{{Slack Message TS}} = '{ timestamp } '" )
210
- logger .debug (f"Returned row: { row } " ) # noqa: G004
262
+ if not row :
263
+ logger .error ("Unable to find record" , extra = {"timestamp" : timestamp })
264
+ error_message = f"Unable to find record with timestamp { timestamp } "
265
+ raise ValueError (error_message )
266
+ logger .info ("Found record" , extra = {"row" : row })
211
267
return self .parse_request_row (row )
0 commit comments