@@ -216,6 +216,19 @@ def __str__(self) -> str:
216216 assert operation_name == "crawl job unknown"
217217
218218
219+ def test_build_operation_name_falls_back_for_broken_string_subclass_identifiers ():
220+ class _BrokenStringIdentifier (str ):
221+ def __str__ (self ) -> str :
222+ raise RuntimeError ("cannot stringify string identifier" )
223+
224+ operation_name = build_operation_name (
225+ "crawl job " ,
226+ _BrokenStringIdentifier ("123" ),
227+ )
228+
229+ assert operation_name == "crawl job unknown"
230+
231+
219232def test_build_operation_name_falls_back_for_unstringifiable_prefixes ():
220233 class _BadPrefix :
221234 def __str__ (self ) -> str :
@@ -229,6 +242,29 @@ def __str__(self) -> str:
229242 assert operation_name == "identifier"
230243
231244
245+ def test_build_operation_name_falls_back_for_broken_string_subclass_prefixes ():
246+ class _BrokenStringPrefix (str ):
247+ def __str__ (self ) -> str :
248+ raise RuntimeError ("cannot stringify string prefix" )
249+
250+ operation_name = build_operation_name (
251+ _BrokenStringPrefix ("crawl job " ),
252+ "identifier" ,
253+ )
254+
255+ assert operation_name == "identifier"
256+
257+
258+ def test_build_fetch_operation_name_falls_back_for_broken_string_subclass_input ():
259+ class _BrokenOperationName (str ):
260+ def __str__ (self ) -> str :
261+ raise RuntimeError ("cannot stringify fetch operation name" )
262+
263+ operation_name = build_fetch_operation_name (_BrokenOperationName ("crawl job" ))
264+
265+ assert operation_name == "Fetching unknown"
266+
267+
232268def test_build_operation_name_sanitizes_control_characters_in_prefix ():
233269 operation_name = build_operation_name (
234270 "crawl\n job\t " ,
0 commit comments