Closed
Description
What is broken.
NetSchoolClient.schools_search keeps a search result only if its id is an integer, and it checks this with isinstance(row.get("id"), int). In Python bool is a subclass of int, so a row whose id is the JSON true or false passes the check. It is shown as a school button in the bot. Picking it binds the class to school id 1 (or 0) under the name the upstream sent with that row. The Petersburg mapper already excludes bool before int for exactly this reason (providers/petersburg/mapper.py, text and number). The netschool client has no such guard.
The failure scenario.
- An admin opens «⚙️ Класс», chooses to bind «Сетевой город», picks a region and types a school name.
- The region's
/webapi/schools/searchanswers with a row such as{"id": true, "name": "Школа № 5"}. The row can be malformed, from a different API version, or have a boolean placeholder in place of the number. schools_searchkeeps it as{"id": True, "name": "Школа № 5"}. The bot stores the list in FSM data, which goes through JSON, sotruecomes back asTrue. «Школа № 5» is drawn as a button under «Выберите школу:».- The admin presses it.
class_diary_schoolrunsint(school["id"]), which gives1. The class is saved withdiary_school_id = 1anddiary_school_name = "Школа № 5". The audit records «привязан «Сетевой город»: …, Школа № 5», and the bot answers «Дневник привязан». providers/diary/registry.pyonly checks thatdiary_school_idis notNone, so the binding counts as valid. Every family sign-in for that class is then sent upstream with school id1, which is a different school or none at all. The class card still shows the name the admin picked, so nothing shows the id is wrong. A row with"id": falsedoes the same with school id0.
Where.
server/app/providers/netschool/client.py:446: the filterisinstance(row.get("id"), int), which accepts aboolserver/app/providers/netschool/client.py:447: the kept row carriesrow["id"]through unchangedserver/app/bot/handlers/manage.py:2522: the only caller;:2530puts the list in FSM dataserver/app/bot/handlers/manage.py:2584:school_class.diary_school_id = int(school["id"])turnsTrueinto1server/app/providers/diary/registry.py:81-87: the binding is accepted because the id is notNoneserver/app/providers/petersburg/mapper.py:152-165: the existing rule («boolis anintin Python») that this client does not follow
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
Let a phone register a diary session it opened itself, and fix what t…