Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

SPOT : UserDataStreamEventsResponse does not deserialize correctly, instance is always None

已关闭
#477 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
api

调研方向

从 UserDataStreamEventsResponse.model_validate 和相关的具体事件模型开始,然后将判别联合的行为与 #476 中的 SymbolFilters 问题以及相关问题 #405 进行比较。当诸如 balanceUpdate 这样的事件生成一个类型化的事件实例并保留其字段,而不是让 actual_instance 保持为 None 时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Answered
Description

The UserDataStreamEventsResponse model fails to parse user data stream events into their concrete event types (BalanceUpdate, ExecutionReport, OutboundAccountPosition, EventStreamTerminated, etc.). All input results in None and the event data is completely lost.

Expected Behavior

When validating a user data stream event, the model should:

  1. Parse the event dictionary into the appropriate concrete event type based on the "e" field
  2. Return a strongly-typed instance (e.g., BalanceUpdate, ExecutionReport)
  3. Preserve all event data fields

Example:

from binance_sdk_spot.websocket_api.models import UserDataStreamEventsResponse

event = {
    "e": "balanceUpdate",
    "E": 1573200697110,
    "a": "BTC",
    "d": "100.00000000",
    "T": 1573200697068
}

result = UserDataStreamEventsResponse.model_validate(event)
# Expected: result is a BalanceUpdate instance with all fields accessible
# Expected: result.a == "BTC"
# Expected: result.d == "100.00000000"
# Expected: result.E == 1573200697110
# Expected: result.e == "balanceUpdate"
# Expected: result.T == 1573200697068
Actual Behavior

The parsing always fails and returns None, losing all event data:

result = UserDataStreamEventsResponse.model_validate(event)
# Actual: result.actual_instance is None
# Actual: All event data is lost
# Actual: Cannot access event fields
Possible Root Cause

The model uses Pydantic's discriminated union pattern but fails to properly discriminate between event types. Issues include:

  1. Schema Validation Failure: The discriminator field or schema mapping is not correctly configured
  2. Type Resolution Failure: The model cannot resolve which concrete event type to instantiate
  3. Silent Failure: Instead of raising validation errors, it silently returns None

This is similar to the SymbolFilters discriminated union issue that was previously identified, where filter type discrimination failed.

Impact
  • Complete Data Loss: All user data stream events are lost when using this model
  • No Balance Updates: Balance changes from outboundAccountPosition events cannot be processed
  • No Order Updates: Order status changes from executionReport events cannot be tracked
  • No Stream Monitoring: Stream termination events cannot be detected
Related Issues
  • Similar to #476 discriminated union parsing issue
References

Affected Version: >=2.1.0
Related or same as #405

主要语言
Python
星标
3k
派生
712
平均合并
1 天 5 小时
30 天内合并 PR
4

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

binance/binance-connector-python 的其他 Issue

查看 binance/binance-connector-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。