Skip to content

fix: parse bot account profiles#66

Merged
ink-developer merged 2 commits into
MaxApiTeam:dev/2.3.1from
MikeMike88:fix/user-bot-fields
Jun 19, 2026
Merged

fix: parse bot account profiles#66
ink-developer merged 2 commits into
MaxApiTeam:dev/2.3.1from
MikeMike88:fix/user-bot-fields

Conversation

@MikeMike88

@MikeMike88 MikeMike88 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Описание

Боты MAX в ответе get_user присылают gender числовым кодом, а web_app
строкой-ссылкой вместо объекта. Из-за строгих типов модели User
model_validate падает с ValidationError, и контакт-бот не подтягивается
(воспроизводится на боте «Алиса AI»).

Расширяю типы двух полей:

  • gender: str | int | None
  • web_app: dict[str, Any] | str | None

Вариант dict у web_app сохранён для обратной совместимости. Обратной
несовместимости нет: у обычных пользователей и у профилей с прежними типами
всё работает как раньше.

Тип изменений

  • Исправление бага
  • Новая функциональность
  • Улучшение документации
  • Рефакторинг

Связанные задачи / Issue

Ссылка на issue, если есть: #

Тестирование

Добавлены регрессионные тесты в tests/domain/test_user_models.py:

from pymax.types.domain import User

# Бот: gender числом, web_app строкой-ссылкой — раньше падало с ValidationError
user = User.model_validate({
    "id": 6738397,
    "names": [{"name": "Алиса AI", "type": "NICK"}],
    "gender": 1,
    "webApp": "https://alice.yandex.ru/max_onboarding",
})
assert user.gender == 1
assert user.web_app == "https://alice.yandex.ru/max_onboarding"

Запуск:

pytest tests/domain/test_user_models.py

Summary by CodeRabbit

  • Improvements

    • Enhanced API compatibility to handle flexible data formats for user profile information
  • Tests

    • Added test coverage for user data parsing with various payload structures

ink-developer and others added 2 commits June 18, 2026 21:50
MAX bots send `gender` as a numeric code and `web_app` as a URL string
instead of an object, so `User.model_validate` raised a ValidationError
and the bot user failed to load. Widen both field types
(gender: str | int, web_app: dict | str) and add regression tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a2ae4453-6b09-4943-a606-0952618174ad

📥 Commits

Reviewing files that changed from the base of the PR and between ff3af5b and d1435b6.

📒 Files selected for processing (2)
  • src/pymax/types/domain/user.py
  • tests/domain/test_user_models.py

📝 Walkthrough

Walkthrough

The User domain model's gender field is expanded from str | None to str | int | None, and web_app from dict[str, Any] | None to dict[str, Any] | str | None. Docstrings are updated to match. A new test module covers bot-style, human, and dict web_app payload shapes.

Changes

User Model Field Type Expansion

Layer / File(s) Summary
User field type annotations expanded
src/pymax/types/domain/user.py
Docstring and runtime annotations for gender updated to str | int | None and web_app updated to dict[str, Any] | str | None, with inline comments documenting alternate API payload forms.
Tests for expanded User field types
tests/domain/test_user_models.py
New test module asserting bot payloads (numeric gender, URL web_app), minimal human payloads (gender and web_app are None), and backward-compatible dict web_app all parse correctly.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 Two fields grew wide, to hold more shapes,
An int, a string — no parsing escapes!
The bot sends a number, a URL in tow,
The human sends nothing, None steals the show.
Our tests hop along and prove it holds true —
More types, more joy, the model breaks through! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: extending the User model to handle non-standard bot API payload shapes for gender and web_app fields.
Description check ✅ Passed The description follows the template structure completely, includes a clear explanation in Russian, specifies the bug fix type, provides concrete test examples, and explains backward compatibility.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ink-developer ink-developer changed the base branch from main to dev/2.3.1 June 19, 2026 15:17
@ink-developer

Copy link
Copy Markdown
Collaborator

Спасибо за PR!

@ink-developer ink-developer merged commit 0a72906 into MaxApiTeam:dev/2.3.1 Jun 19, 2026
7 checks passed
@ink-developer ink-developer mentioned this pull request Jun 19, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants