fix: корректный тип payload для share-вложения (closes #108)#109
Merged
love-apples merged 1 commit intolove-apples:mainfrom Apr 14, 2026
Merged
Conversation
Входящий attachment с type="share" теперь десериализуется
с payload типа ShareAttachmentPayload вместо OtherAttachmentPayload,
так что пользовательский pattern-matching на типе payload работает
как ожидается.
- Добавлен класс ShareAttachmentPayload ({url, token})
- Share.payload переопределён как ShareAttachmentPayload | None
- ShareAttachmentPayload экспортирован из maxapi.types
- Регрессионные тесты: share корректно резолвится, File/Audio/Video
продолжают использовать OtherAttachmentPayload
Closes love-apples#108
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
bish-x
added a commit
to bish-x/maxapi
that referenced
this pull request
Apr 14, 2026
Подтянуты PR из upstream: love-apples#93 (FSM), love-apples#96 (download_file), love-apples#101 (fetch user/chat), love-apples#105 (ClipboardButton), love-apples#109 (share payload), love-apples#110 (webhook secret warning). Конфликт в tests/test_types.py: принят upstream-стиль (явный update_type, разнесённые assert). Сохранены доп. тесты test_get_ids_ignores_inviter_id / test_get_ids_ignores_admin_id — их purpose именно цель PR love-apples#94 (не путать inviter_id/admin_id с user.user_id).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Что делает PR
Фикс для #108. Входящий attachment с
type="share"теперь десериализуется сpayloadтипаShareAttachmentPayloadвместоOtherAttachmentPayload(который по докстрингу «для файлов»), так что пользователь может делать pattern-matching:Root cause
Attachmentsunion (maxapi/types/attachments/__init__.py) — discriminated поtype, поэтому сам attachment корректно резолвится вShare.Share.payloadнаследовался от базовогоAttachment, а в его union (attachment.py) не былоShareAttachmentPayload.OtherAttachmentPayload={url, token | None}— суперсет для payload share-а, pydantic smart-union (2.x) выбирал его первым.Что меняется
ShareAttachmentPayloadсurl: str,token: strвmaxapi/types/attachments/attachment.py.Shareпереопределяетpayload: ShareAttachmentPayload | None = None. Это ключевая правка — она локализует фикс именно вShare, не затрагивая payload уFile/Audio/Video(они продолжают работать черезOtherAttachmentPayload).ShareAttachmentPayloadтакже добавлен в базовыйAttachment.payload-union послеOtherAttachmentPayload— чтобы явная сборкаAttachment(type=SHARE, payload=ShareAttachmentPayload(...))была типобезопасна, без регрессии на File/Audio/Video.ShareAttachmentPayloadэкспортирован изmaxapi.types.Тесты
test_share_attachment_payload_deserialize— регрессия Нет типа вложения share -> ошибка определения вложения OtherAttachmentPayload (файл) #108 (share →Share+ShareAttachmentPayload).test_file_attachment_payload_unchanged_by_share_fix— страховка, чтоFileпо-прежнему получаетOtherAttachmentPayload.Локальный прогон:
tests/test_serialization_models.py— все 7 тестов зелёные, полный прогон (кромеtest_webhook, где нет опциональных зависимостей, иtest_dispatcher, где нетaresponses) — 494 passed.Нотки
OtherAttachmentPayload— они у файлов/аудио/видео остаются прежними.maxapi==0.9.18, фикс проверен на ветке.