Coverage for celery_tasks/exceptions.py: 33.33%

9 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2026-11-30 20:17 +0000

1"""Exceptions that distinguish permanent ingest failures from transient ones. 

2 

3`process_match_data` retries on any exception with exponential backoff, which 

4is right for a database blip and wrong for a name that does not exist. An 

5unknown team is not going to become known by waiting ten minutes; retrying it 

6three times only delays the moment anyone finds out. 

7 

8Raising one of these marks the failure as permanent. The task's 

9`dont_autoretry_for` skips the retry wrapper for it, and the handler records 

10the name in `ingest_failures` so it is reported once, with a count, instead of 

11disappearing into a worker log. 

12""" 

13 

14from __future__ import annotations 

15 

16 

17class UnresolvedNameError(Exception): 

18 """A name in the feed does not correspond to anything in the database. 

19 

20 Attributes: 

21 kind: What kind of name it was — 'team', 'division', 'league' or 

22 'invalid'. Matches ingest_failures.kind. 

23 raw_name: The string exactly as the feed sent it. Kept verbatim 

24 because the fix is `mt team alias add <team> "<raw_name>"`, and a 

25 normalised copy would not be the string that needs aliasing. 

26 league: The league as the feed named it, or None. 

27 sample: One example of the match that was dropped, for the alert. 

28 """ 

29 

30 def __init__( 

31 self, 

32 kind: str, 

33 raw_name: str, 

34 *, 

35 league: str | None = None, 

36 sample: str | None = None, 

37 ) -> None: 

38 self.kind = kind 

39 self.raw_name = raw_name 

40 self.league = league 

41 self.sample = sample 

42 scope = f" (league={league})" if league else "" 

43 super().__init__(f"{kind.capitalize()} not found: {raw_name}{scope}")