librus-python-api 1.11.5__tar.gz → 1.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/API.md +7 -1
  2. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/CHANGELOG.md +30 -0
  3. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/PKG-INFO +7 -4
  4. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/README.md +6 -3
  5. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/__init__.py +1 -1
  6. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/attendance_frequency.py +39 -0
  7. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/config.py +25 -0
  8. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/markup.py +11 -3
  9. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/models.py +12 -0
  10. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/parsers.py +20 -7
  11. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/service.py +103 -27
  12. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/.gitignore +0 -0
  13. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/LICENSE +0 -0
  14. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/SECURITY.md +0 -0
  15. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/pyproject.toml +0 -0
  16. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/_notification_bootstrap.py +0 -0
  17. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/_notification_codec.py +0 -0
  18. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/_storage.py +0 -0
  19. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/_windows_filesystem.py +0 -0
  20. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/announcements.py +0 -0
  21. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/attachment_routes.py +0 -0
  22. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/attachments.py +0 -0
  23. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/attendance.py +0 -0
  24. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/budget.py +0 -0
  25. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/checkpoint.py +0 -0
  26. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/class_free_days.py +0 -0
  27. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/completed_lessons.py +0 -0
  28. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/detail_fields.py +0 -0
  29. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/diagnostics.py +0 -0
  30. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/exceptions.py +0 -0
  31. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/files.py +0 -0
  32. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/formative_grades.py +0 -0
  33. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/gateway_grades.py +0 -0
  34. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/grade_parsers.py +0 -0
  35. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/grade_records.py +0 -0
  36. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/homework_range.py +0 -0
  37. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/inspect_page.py +0 -0
  38. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/justifications.py +0 -0
  39. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/lifecycle.py +0 -0
  40. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/message_content.py +0 -0
  41. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/messages.py +0 -0
  42. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/modern_body.py +0 -0
  43. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/modern_mailbox.py +0 -0
  44. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/modern_messages.py +0 -0
  45. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/notification_models.py +0 -0
  46. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/notification_persistence.py +0 -0
  47. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/notification_workflow.py +0 -0
  48. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/notifications.py +0 -0
  49. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/parsing.py +0 -0
  50. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/persistence.py +0 -0
  51. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/py.typed +0 -0
  52. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/recipients.py +0 -0
  53. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/scheduler.py +0 -0
  54. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/school_reads.py +0 -0
  55. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/school_year_archive.py +0 -0
  56. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/sending.py +0 -0
  57. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/timetable.py +0 -0
  58. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/src/librus_python_api/transport.py +0 -0
  59. {librus_python_api-1.11.5 → librus_python_api-1.12.0}/uv.lock +0 -0
@@ -440,7 +440,9 @@ school's login. See [gateway descriptive grades](contracts/grades.md#gateway-des
440
440
  - `attendance_detail(detail_id)` takes a numeric string and returns ordered
441
441
  `fields`, `notes` and stable-key `normalized_fields` (see below).
442
442
  - `gateway_attendance()` returns the JSON records with a strict `AttendanceKind`
443
- per stable type ID; unknown IDs stay `UNKNOWN`. A record's `identifier` is an
443
+ per stable type ID. A type outside that policy takes the kind of the standard
444
+ type the school's type list names for it (1.12.0; the list is read only when
445
+ needed); one the list cannot map stays `UNKNOWN`. A record's `identifier` is an
444
446
  opaque token of up to 64 printable ASCII characters, not always digits
445
447
  (1.11.5); it only detects duplicate records.
446
448
  - `attendance_frequency()` returns per-semester and overall `FrequencyMeasure`
@@ -448,6 +450,10 @@ school's login. See [gateway descriptive grades](contracts/grades.md#gateway-des
448
450
  Unknown types or an empty denominator give `ratio=None`, never 100 %.
449
451
  - `subject_frequency(start=None, end=None)` resolves lessons to subjects through
450
452
  a 256-entry, one-hour metadata cache and returns one measure per subject ID.
453
+ Records whose lesson or subject Librus does not give are counted in
454
+ `unresolved` (a subject-policy `FrequencyMeasure`, `None` when all resolved)
455
+ instead of failing the read (1.12.0). When nothing resolved, the first lookup
456
+ error is raised.
451
457
 
452
458
  ## Timetable
453
459
 
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.12.0 (2026-11-24) - Attendance on schools' own types; colons in grade comments
4
+
5
+ Follow-ups to librus-mcp#136, found by comparing each check with public Librus
6
+ clients before the tester's next run:
7
+
8
+ - Attendance types: a record whose type is outside the fixed type policy was
9
+ `unknown`, which made every frequency ratio `None`. Such a type is now
10
+ resolved through the school's type list (`/gateway/api/2.0/Attendances/Types`,
11
+ new route `attendance_types`): a school's own type counts as the standard
12
+ type it names (absence, late, excused, exemption or present). The list is
13
+ read only when a record needs it, one more request; a parsed list is reused
14
+ for an hour per login, and an unusable one is read again on the next call.
15
+ When it is unavailable, those records stay `unknown` as before.
16
+ - Subject frequency: a lesson or subject that Librus does not give (an HTTP
17
+ failure, a denial or an unexpected body) failed the whole
18
+ `subject_frequency()` read. Its records are now counted in the new
19
+ `SubjectFrequencies.unresolved` measure, `None` when every record resolved.
20
+ When nothing resolved, the read fails with the first lookup's error, since
21
+ that is a failing route rather than a missing record. An exhausted budget,
22
+ an expired session, throttling, maintenance and cancellation still fail.
23
+ - Grades: a line such as `Word: text` inside a grade's comment, skill or
24
+ grading area started a field of its own, and the next plain line failed the
25
+ whole grades read with `ParseError`. A line whose label is not a Librus label
26
+ now continues the free text; a Librus label such as `Waga` still starts its
27
+ own field.
28
+ - Diagnostics: a gateway validation failure named only its first three
29
+ errors, so one field repeated on many records hid any other. Errors that
30
+ differ only in a record index are now one entry with a count, such as
31
+ `Attendances[*].Id string_pattern_mismatch x4`, up to five entries.
32
+
3
33
  ## 1.11.5 (2026-11-23) - Parent logins: attendance frequency and long grade tooltips
4
34
 
5
35
  The two failures left on a tester's parent login (librus-mcp#136):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: librus-python-api
3
- Version: 1.11.5
3
+ Version: 1.12.0
4
4
  Summary: Independent bounded async Librus Synergia client
5
5
  Project-URL: Repository, https://github.com/krzysztofbury/librus-python-api
6
6
  Project-URL: Issues, https://github.com/krzysztofbury/librus-python-api/issues
@@ -42,7 +42,10 @@ private ACLs. Windows installations include `pywin32` and `tzdata` automatically
42
42
  Network paths, reparse-point paths and unsafe storage permissions fail closed.
43
43
  See [platform requirements](contracts/persistence.md#windows-disk-boundary-25).
44
44
 
45
- **Status:** `1.11.5` reads gateway attendance records whose ID is not a
45
+ **Status:** `1.12.0` resolves a school's own attendance types, counts
46
+ attendance whose lesson or subject cannot be resolved apart instead of failing
47
+ the subject frequency read, keeps grade comment lines that hold a colon as
48
+ text and groups repeated gateway validation errors. `1.11.5` reads gateway attendance records whose ID is not a
46
49
  number and grade tooltips longer than 32 lines. `1.11.4` recovers the messages sign-in after a page that ended the
47
50
  session, reports e-Justifications switched off for a parent login as
48
51
  `ViewDisabledError`, reads descriptive grade skills that wrap onto a second
@@ -90,7 +93,7 @@ See [limitations](#supported-features-and-limitations) below.
90
93
  Install the exact release from PyPI after its gated publication completes:
91
94
 
92
95
  ```sh
93
- python -m pip install librus-python-api==1.11.5
96
+ python -m pip install librus-python-api==1.12.0
94
97
  ```
95
98
 
96
99
  Pin the exact version qualified by your application. Before publication, use a
@@ -106,7 +109,7 @@ python -m pip install .
106
109
  To install a locally built wheel instead:
107
110
 
108
111
  ```sh
109
- python -m pip install ./dist/librus_python_api-1.11.5-py3-none-any.whl
112
+ python -m pip install ./dist/librus_python_api-1.12.0-py3-none-any.whl
110
113
  ```
111
114
 
112
115
  No console script or background process is installed: import the library in your
@@ -16,7 +16,10 @@ private ACLs. Windows installations include `pywin32` and `tzdata` automatically
16
16
  Network paths, reparse-point paths and unsafe storage permissions fail closed.
17
17
  See [platform requirements](contracts/persistence.md#windows-disk-boundary-25).
18
18
 
19
- **Status:** `1.11.5` reads gateway attendance records whose ID is not a
19
+ **Status:** `1.12.0` resolves a school's own attendance types, counts
20
+ attendance whose lesson or subject cannot be resolved apart instead of failing
21
+ the subject frequency read, keeps grade comment lines that hold a colon as
22
+ text and groups repeated gateway validation errors. `1.11.5` reads gateway attendance records whose ID is not a
20
23
  number and grade tooltips longer than 32 lines. `1.11.4` recovers the messages sign-in after a page that ended the
21
24
  session, reports e-Justifications switched off for a parent login as
22
25
  `ViewDisabledError`, reads descriptive grade skills that wrap onto a second
@@ -64,7 +67,7 @@ See [limitations](#supported-features-and-limitations) below.
64
67
  Install the exact release from PyPI after its gated publication completes:
65
68
 
66
69
  ```sh
67
- python -m pip install librus-python-api==1.11.5
70
+ python -m pip install librus-python-api==1.12.0
68
71
  ```
69
72
 
70
73
  Pin the exact version qualified by your application. Before publication, use a
@@ -80,7 +83,7 @@ python -m pip install .
80
83
  To install a locally built wheel instead:
81
84
 
82
85
  ```sh
83
- python -m pip install ./dist/librus_python_api-1.11.5-py3-none-any.whl
86
+ python -m pip install ./dist/librus_python_api-1.12.0-py3-none-any.whl
84
87
  ```
85
88
 
86
89
  No console script or background process is installed: import the library in your
@@ -1,7 +1,7 @@
1
1
  """Independent bounded async client. General live compatibility is unqualified."""
2
2
 
3
3
  # Before the imports: config reads it for the User-Agent.
4
- __version__ = "1.11.5"
4
+ __version__ = "1.12.0"
5
5
 
6
6
  from librus_python_api.attachments import AttachmentStream, ModernAttachmentStream
7
7
  from librus_python_api.budget import RequestBudget
@@ -1,5 +1,8 @@
1
1
  """Original validated gateway parsing and explicit attendance ratio policies."""
2
2
 
3
+ from collections.abc import Mapping
4
+ from dataclasses import replace
5
+
3
6
  from pydantic import BaseModel
4
7
 
5
8
  from librus_python_api import markup
@@ -7,6 +10,8 @@ from librus_python_api.config import (
7
10
  ATTENDANCE_MAX_LESSONS,
8
11
  ATTENDANCE_MAX_RECORDS,
9
12
  ATTENDANCE_MAX_SUBJECTS,
13
+ ATTENDANCE_MAX_TYPES,
14
+ ATTENDANCE_STANDARD_TYPE_KINDS,
10
15
  ATTENDANCE_TYPE_KINDS,
11
16
  )
12
17
  from librus_python_api.exceptions import ErrorKind, LibrusError
@@ -15,6 +20,7 @@ from librus_python_api.models import (
15
20
  FrequencyMeasure,
16
21
  GatewayAttendanceRecord,
17
22
  _AttendanceEnvelopeWire,
23
+ _AttendanceTypesEnvelopeWire,
18
24
  _LessonEnvelopeWire,
19
25
  _LessonsEnvelopeWire,
20
26
  _SubjectEnvelopeWire,
@@ -117,6 +123,39 @@ def parse_subject_names(body: bytes) -> dict[str, str]:
117
123
  )
118
124
 
119
125
 
126
+ def parse_attendance_types(body: bytes) -> dict[str, str]:
127
+ """Map a school's own attendance type IDs to the kind of their standard type.
128
+
129
+ Types without a known standard type are omitted and stay unknown.
130
+ """
131
+ envelope = _collection(
132
+ decode_json(body), "Types", ATTENDANCE_MAX_TYPES, _AttendanceTypesEnvelopeWire
133
+ )
134
+ return _unique(
135
+ [
136
+ (kind.Id, ATTENDANCE_STANDARD_TYPE_KINDS[kind.StandardType.Id])
137
+ for kind in envelope.Types
138
+ if kind.StandardType is not None
139
+ and kind.StandardType.Id in ATTENDANCE_STANDARD_TYPE_KINDS
140
+ ]
141
+ )
142
+
143
+
144
+ def resolve_type_kinds(
145
+ rows: tuple[GatewayAttendanceRecord, ...], kinds: Mapping[str, str]
146
+ ) -> tuple[GatewayAttendanceRecord, ...]:
147
+ """Rows of an unknown type take the kind `kinds` gives their type, if any.
148
+
149
+ The fixed ATTENDANCE_TYPE_KINDS policy always wins over a school's list.
150
+ """
151
+ return tuple(
152
+ replace(row, kind=AttendanceKind(kinds[row.type_id]))
153
+ if row.kind == "unknown" and row.type_id in kinds
154
+ else row
155
+ for row in rows
156
+ )
157
+
158
+
120
159
  def summarize_frequency(
121
160
  rows: tuple[GatewayAttendanceRecord, ...],
122
161
  *,
@@ -538,6 +538,17 @@ ENDPOINTS: Mapping[str, Endpoint] = MappingProxyType(
538
538
  True,
539
539
  Evidence.INDEPENDENTLY_OBSERVED,
540
540
  ),
541
+ # Read only when a record's type is outside ATTENDANCE_TYPE_KINDS.
542
+ # Shape from public client sources and a public sample (custom
543
+ # types name their standard type); not yet seen on an owner login.
544
+ Endpoint(
545
+ "attendance_types",
546
+ "GET",
547
+ "/gateway/api/2.0/Attendances/Types",
548
+ SideEffect.NONE,
549
+ True,
550
+ Evidence.SOURCE_INFORMED,
551
+ ),
541
552
  Endpoint(
542
553
  "attendance_lesson",
543
554
  "GET",
@@ -908,6 +919,7 @@ ATTENDANCE_MAX_WINDOW_DAYS = 371
908
919
  # Whole-school gateway collections resolve attendance metadata in two requests.
909
920
  ATTENDANCE_MAX_LESSONS = 4096
910
921
  ATTENDANCE_MAX_SUBJECTS = 1024
922
+ ATTENDANCE_MAX_TYPES = 1024
911
923
  # Collection recognition and detail retrieval share this central path family.
912
924
  ATTENDANCE_DETAIL_PATH_PREFIX = "/przegladaj_nb/szczegoly/"
913
925
  # Recognition only: formative detail links are classified, never requested.
@@ -1088,6 +1100,8 @@ PAGE_NOTICES = MappingProxyType(
1088
1100
  }
1089
1101
  )
1090
1102
  MODULE_UNAVAILABLE_PATH = "/modul_niedostepny"
1103
+ # Distinct field and rule pairs a wire validation failure names.
1104
+ WIRE_FAILURE_GROUPS = 5
1091
1105
  CLASS_FREE_DAYS_MAX_RECORDS = 4096
1092
1106
  # e-Justifications list (`/eusprawiedliwienia`, structure observed on two
1093
1107
  # parent logins on 2026-11-13). The list table's classes, its seven header
@@ -1667,6 +1681,17 @@ ATTENDANCE_TYPE_KINDS = MappingProxyType(
1667
1681
  "2829": "training",
1668
1682
  }
1669
1683
  )
1684
+ # A school's own attendance type names one of the standard types it counts
1685
+ # as (`StandardType`); public clients map them this way (librus-mcp#136).
1686
+ ATTENDANCE_STANDARD_TYPE_KINDS = MappingProxyType(
1687
+ {
1688
+ "1": "absence",
1689
+ "2": "late",
1690
+ "3": "excused",
1691
+ "4": "exemption",
1692
+ "100": "present",
1693
+ }
1694
+ )
1670
1695
 
1671
1696
 
1672
1697
  class _ValidatedConfig(BaseModel):
@@ -96,9 +96,10 @@ def tooltip_fields(
96
96
  A free-text field may span lines; an unlabelled line after it continues
97
97
  its value. Any other unlabelled line is an unknown layout. With `heading`,
98
98
  the first line is taken whole, colon included, and appended to it.
99
- `multiline` names the free-text labels (default `Komentarz`); with
100
- `unknown_multiline`, a field whose label is not a known one (teacher text
101
- holding a colon) is free text too, and inside such free text a line
99
+ `multiline` names the free-text labels (default `Komentarz`); a line
100
+ inside one whose label is no known label (teacher text holding a colon)
101
+ continues it too. With `unknown_multiline`, such a line starts a field of
102
+ its own that is free text as well, and inside free text a line
102
103
  starting with a known label is text unless the tooltip's closing run of
103
104
  known-label lines begins there. Otherwise a known label such as `Data`
104
105
  never continues. A repeatable label (`Poprawa oceny`) adds its value as
@@ -136,6 +137,13 @@ def tooltip_fields(
136
137
  )
137
138
  and (
138
139
  not separator
140
+ # Teacher text holding a colon inside a labelled free-text field
141
+ # such as `Komentarz` (librus-mcp#136): no Librus label, so text.
142
+ or (
143
+ not unknown_multiline
144
+ and last in multiline
145
+ and key not in TOOLTIP_LABELS
146
+ )
139
147
  or (unknown_multiline and index < closing and key in TOOLTIP_LABELS)
140
148
  )
141
149
  ):
@@ -1408,6 +1408,9 @@ class SubjectFrequencies:
1408
1408
  start: date | None
1409
1409
  end: date | None
1410
1410
  observation: Observation
1411
+ # Attendance whose lesson or subject Librus could not resolve; None when
1412
+ # every record resolved.
1413
+ unresolved: FrequencyMeasure | None = None
1411
1414
 
1412
1415
 
1413
1416
  class _NumericReferenceWire(BaseModel):
@@ -1450,6 +1453,15 @@ class _AttendanceEnvelopeWire(BaseModel):
1450
1453
  Attendances: Annotated[list[_AttendanceWire], Field(max_length=2048)]
1451
1454
 
1452
1455
 
1456
+ class _AttendanceTypeWire(_NumericReferenceWire):
1457
+ StandardType: _NumericReferenceWire | None = None
1458
+
1459
+
1460
+ class _AttendanceTypesEnvelopeWire(BaseModel):
1461
+ model_config = ConfigDict(strict=True, extra="ignore", hide_input_in_errors=True)
1462
+ Types: list[_AttendanceTypeWire]
1463
+
1464
+
1453
1465
  class _LessonWire(_NumericReferenceWire):
1454
1466
  Subject: _NumericReferenceWire
1455
1467
 
@@ -18,6 +18,7 @@ from librus_python_api.config import (
18
18
  PROFILE_LABELS,
19
19
  PROFILE_LUCKY_NUMBER_CLASS,
20
20
  PROFILE_LUCKY_NUMBER_DISABLED,
21
+ WIRE_FAILURE_GROUPS,
21
22
  )
22
23
  from librus_python_api.exceptions import ErrorKind, LibrusError, ParseError
23
24
  from librus_python_api.models import (
@@ -288,20 +289,32 @@ def wire_failure(error: ValidationError, model: type[BaseModel]) -> str:
288
289
  """Where a wire model rejected a body: field path and rule, never a value.
289
290
 
290
291
  A path part is shown only when it is a list index or a field name of
291
- `model`; anything else (such as a dict key from the body) is `?`.
292
+ `model`; anything else (such as a dict key from the body) is `?`. Errors
293
+ that differ only in a list index are one entry, `[*]` with a count, so a
294
+ different field is never hidden behind repeats of the first one
295
+ (librus-mcp#136 showed three of four errors, all the same field).
292
296
  """
293
297
  names = _wire_names(model, set())
294
298
  errors = error.errors(include_url=False, include_context=False, include_input=False)
295
- shown: list[str] = []
296
- for item in errors[:3]:
297
- path = ""
299
+ groups: dict[tuple[str, str], list[str]] = {}
300
+ for item in errors:
301
+ path = pattern = ""
298
302
  for part in item["loc"]:
299
303
  if type(part) is int:
300
304
  path += f"[{part}]"
305
+ pattern += "[*]"
301
306
  else:
302
- path += ("." if path else "") + (part if part in names else "?")
303
- shown.append(f"{path or '(body)'} {item['type']}")
304
- more = f"; {len(errors)} errors" if len(errors) > 3 else ""
307
+ name = ("." if path else "") + (part if part in names else "?")
308
+ path += name
309
+ pattern += name
310
+ groups.setdefault((pattern or "(body)", item["type"]), []).append(
311
+ path or "(body)"
312
+ )
313
+ shown = [
314
+ f"{paths[0]} {rule}" if len(paths) == 1 else f"{pattern} {rule} x{len(paths)}"
315
+ for (pattern, rule), paths in list(groups.items())[:WIRE_FAILURE_GROUPS]
316
+ ]
317
+ more = f"; {len(errors)} errors" if len(groups) > WIRE_FAILURE_GROUPS else ""
305
318
  return "; ".join(shown) + more
306
319
 
307
320
 
@@ -19,11 +19,13 @@ from librus_python_api.announcements import parse_announcements
19
19
  from librus_python_api.attachments import AttachmentStream, ModernAttachmentStream
20
20
  from librus_python_api.attendance import parse_attendance, parse_attendance_detail
21
21
  from librus_python_api.attendance_frequency import (
22
+ parse_attendance_types,
22
23
  parse_gateway_attendance,
23
24
  parse_lesson_subject,
24
25
  parse_lesson_subjects,
25
26
  parse_subject_name,
26
27
  parse_subject_names,
28
+ resolve_type_kinds,
27
29
  summarize_frequency,
28
30
  )
29
31
  from librus_python_api.budget import RequestBudget
@@ -438,6 +440,21 @@ _READ_STATUS: contextvars.ContextVar[list[int | None] | None] = contextvars.Cont
438
440
  _METADATA_MAP_FALLBACK = frozenset(
439
441
  {ErrorKind.ACCESS_DENIED, ErrorKind.CONNECTION, ErrorKind.LIMIT, ErrorKind.PARSE}
440
442
  )
443
+ _METADATA_MAP_PARSERS: Mapping[str, Callable[[bytes], dict[str, str]]] = (
444
+ MappingProxyType(
445
+ {
446
+ "attendance_lessons": parse_lesson_subjects,
447
+ "attendance_subjects": parse_subject_names,
448
+ "attendance_types": parse_attendance_types,
449
+ }
450
+ )
451
+ )
452
+ # A single lesson or subject Librus does not give (an HTTP failure, a denial or
453
+ # an unexpected body): its attendance is counted as unresolved instead of
454
+ # failing the whole read, as public clients do. An exhausted budget stays LIMIT.
455
+ _UNRESOLVED_REFERENCE = frozenset(
456
+ {ErrorKind.ACCESS_DENIED, ErrorKind.CONNECTION, ErrorKind.PARSE}
457
+ )
441
458
 
442
459
 
443
460
  class AccountClient:
@@ -1565,11 +1582,14 @@ class AccountClient:
1565
1582
  self, *, budget: RequestBudget | None = None, max_age_seconds: float = 0.0
1566
1583
  ) -> GatewayAttendance:
1567
1584
  async def fetch(budget: RequestBudget, _: bool) -> GatewayAttendance:
1568
- items = await self._page(
1569
- "gateway_attendance",
1585
+ items = await self._typed(
1586
+ await self._page(
1587
+ "gateway_attendance",
1588
+ budget,
1589
+ parse_gateway_attendance,
1590
+ content_type=JSON,
1591
+ ),
1570
1592
  budget,
1571
- parse_gateway_attendance,
1572
- content_type=JSON,
1573
1593
  )
1574
1594
  return GatewayAttendance(
1575
1595
  self._session_identity(),
@@ -2647,11 +2667,7 @@ class AccountClient:
2647
2667
  cached = self._metadata_maps.get(endpoint)
2648
2668
  if cached and time.monotonic() - cached[0] <= ATTENDANCE_METADATA_TTL_SECONDS:
2649
2669
  return cached[1]
2650
- parser = (
2651
- parse_lesson_subjects
2652
- if endpoint == "attendance_lessons"
2653
- else parse_subject_names
2654
- )
2670
+ parser = _METADATA_MAP_PARSERS[endpoint]
2655
2671
  try:
2656
2672
  value: Mapping[str, str] = MappingProxyType(
2657
2673
  await self._page(endpoint, budget, parser, content_type=JSON)
@@ -2676,48 +2692,108 @@ class AccountClient:
2676
2692
  "gateway_attendance", budget, parse_gateway_attendance, content_type=JSON
2677
2693
  )
2678
2694
  observed = self._observation("gateway_attendance")
2679
- rows = tuple(
2680
- r
2681
- for r in collection
2682
- if (start is None or r.day >= start) and (end is None or r.day <= end)
2695
+ rows = await self._typed(
2696
+ tuple(
2697
+ r
2698
+ for r in collection
2699
+ if (start is None or r.day >= start) and (end is None or r.day <= end)
2700
+ ),
2701
+ budget,
2683
2702
  )
2684
2703
  lessons = dict.fromkeys(row.lesson_id for row in rows)
2685
2704
  # Two collection reads keep the request count independent of how many
2686
2705
  # lessons and subjects a student has; the attendance row cap bounds
2687
- # both (#199). References absent from a collection keep the strict
2688
- # per-reference contract, one request each, so fail before spending the
2689
- # budget on lookups it cannot finish.
2706
+ # both (#199). References absent from a collection resolve one request
2707
+ # each, so fail before spending the budget on lookups it cannot finish.
2690
2708
  lesson_map = (
2691
2709
  await self._metadata_map("attendance_lessons", budget) if lessons else {}
2692
2710
  )
2693
2711
  _check_lookups(budget, self._lookups("attendance_lesson", lesson_map, lessons))
2712
+ failures: list[LibrusError] = []
2694
2713
  lesson_subjects = {
2695
2714
  lesson: lesson_map.get(lesson)
2696
- or await self._metadata_value("attendance_lesson", lesson, budget)
2715
+ or await self._reference_or_none(
2716
+ "attendance_lesson", lesson, budget, failures
2717
+ )
2697
2718
  for lesson in lessons
2698
2719
  }
2699
2720
  subjects: dict[str, list[GatewayAttendanceRecord]] = {}
2721
+ unresolved: list[GatewayAttendanceRecord] = []
2700
2722
  for row in rows:
2701
- subjects.setdefault(lesson_subjects[row.lesson_id], []).append(row)
2723
+ subject = lesson_subjects[row.lesson_id]
2724
+ if subject is None:
2725
+ unresolved.append(row)
2726
+ else:
2727
+ subjects.setdefault(subject, []).append(row)
2702
2728
  subject_map = (
2703
2729
  await self._metadata_map("attendance_subjects", budget) if subjects else {}
2704
2730
  )
2705
2731
  _check_lookups(
2706
2732
  budget, self._lookups("attendance_subject", subject_map, subjects)
2707
2733
  )
2708
- items = [
2709
- SubjectFrequency(
2710
- subject,
2711
- subject_map.get(subject)
2712
- or await self._metadata_value("attendance_subject", subject, budget),
2713
- summarize_frequency(tuple(records), subject_policy=True),
2734
+ items: list[SubjectFrequency] = []
2735
+ for subject, records in subjects.items():
2736
+ name = subject_map.get(subject) or await self._reference_or_none(
2737
+ "attendance_subject", subject, budget, failures
2738
+ )
2739
+ if name is None:
2740
+ unresolved.extend(records)
2741
+ continue
2742
+ items.append(
2743
+ SubjectFrequency(
2744
+ subject,
2745
+ name,
2746
+ summarize_frequency(tuple(records), subject_policy=True),
2747
+ )
2714
2748
  )
2715
- for subject, records in subjects.items()
2716
- ]
2749
+ if failures and not items:
2750
+ # Nothing resolved: a failing route, not a missing reference. A
2751
+ # successful all-unresolved result would hide it and be cached.
2752
+ raise failures[0]
2717
2753
  return SubjectFrequencies(
2718
- self._session_identity(), tuple(items), start, end, observed
2754
+ self._session_identity(),
2755
+ tuple(items),
2756
+ start,
2757
+ end,
2758
+ observed,
2759
+ summarize_frequency(tuple(unresolved), subject_policy=True)
2760
+ if unresolved
2761
+ else None,
2719
2762
  )
2720
2763
 
2764
+ async def _reference_or_none(
2765
+ self,
2766
+ endpoint: str,
2767
+ identifier: str,
2768
+ budget: RequestBudget,
2769
+ failures: list[LibrusError],
2770
+ ) -> str | None:
2771
+ """A lesson's subject or a subject's name; None when Librus does not give
2772
+ it, with the failure appended to `failures`.
2773
+
2774
+ An expired session (401 or a login redirect), throttling, maintenance,
2775
+ deadlines, budgets and cancellation still propagate.
2776
+ """
2777
+ try:
2778
+ return await self._metadata_value(endpoint, identifier, budget)
2779
+ except LibrusError as error:
2780
+ if error.kind not in _UNRESOLVED_REFERENCE:
2781
+ raise
2782
+ failures.append(error)
2783
+ return None
2784
+
2785
+ async def _typed(
2786
+ self, rows: tuple[GatewayAttendanceRecord, ...], budget: RequestBudget
2787
+ ) -> tuple[GatewayAttendanceRecord, ...]:
2788
+ """Resolve a school's own attendance types; one read, only when needed.
2789
+
2790
+ A type list Librus cannot give leaves those rows unknown, as before.
2791
+ """
2792
+ if all(row.kind != "unknown" for row in rows):
2793
+ return rows
2794
+ kinds = await self._metadata_map("attendance_types", budget)
2795
+ return resolve_type_kinds(rows, kinds)
2796
+
2721
2797
  # Authentication and response validation.
2722
2798
 
2723
2799
  def _validate_read_response(