Skip to content

fix(types): make ElementAttributes.url optional#57

Open
Sysoev86 wants to merge 1 commit into
MaxApiTeam:mainfrom
Sysoev86:fix/element-attributes-url-optional
Open

fix(types): make ElementAttributes.url optional#57
Sysoev86 wants to merge 1 commit into
MaxApiTeam:mainfrom
Sysoev86:fix/element-attributes-url-optional

Conversation

@Sysoev86
Copy link
Copy Markdown

@Sysoev86 Sysoev86 commented Jun 3, 2026

Проблема

У элементов-анимоджи и стикеров в ответе сервера поля url нет. Из-за строгой модели ElementAttributes.url: str это даёт ValidationError и ломает синхронизацию при логине, когда в истории/сообщениях встречаются такие элементы.

Сервер реально отдаёт ElementAttributes без url, то есть модель сейчас строже самого протокола.

Изменение

 class ElementAttributes(CamelModel):
-    url: str
+    url: str | None = None

Делает url опциональным — по аналогии с уже опциональными полями в Element (from_, attributes). Обратной несовместимости нет: у элементов с url всё работает как прежде.

Контекст

Гоняем PyMax в проде как HTTP-шлюз к MAX. В 2.1.2 вы уже приняли два фикса, которые мы держали локальными патчами (LoginResponse.token → Optional и guard if response.token is not None в app.py) — спасибо! Это последний оставшийся патч, после мержа сможем выпилить локальное патчирование полностью.

Summary by CodeRabbit

  • Bug Fixes
    • The element URL field is now optional instead of required, allowing elements to be created without providing a URL value.

Animoji/sticker elements arrive from the server without a `url` field, so
the strict `url: str` validation raises ValidationError and breaks login
sync. The server returns such elements without `url`, so the model is
stricter than the protocol itself.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

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: a416a86e-4090-4280-834d-599b44df450a

📥 Commits

Reviewing files that changed from the base of the PR and between 473218a and c60927d.

📒 Files selected for processing (1)
  • src/pymax/types/domain/element.py

📝 Walkthrough

Walkthrough

ElementAttributes.url in the domain type contract is changed from a required string field to an optional field accepting str | None with a default of None.

Changes

Element Attributes Type Update

Layer / File(s) Summary
ElementAttributes.url optional field
src/pymax/types/domain/element.py
ElementAttributes.url field type is updated from str to str | None with an explicit default of None, allowing URL to be optional.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops through types with glee,
Some URLs? Optional they'll be!
From must-have strings to None so kind,
The Element now leaves room to find. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: making ElementAttributes.url optional.
Description check ✅ Passed The description covers the problem, solution, and context, but omits the required template sections like explicit type selection checkboxes and a testing example.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

1 participant