Typed value for the peer view of a transfer session

未關閉
#369 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
72/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
api, backend

研究方向

First check the dependency in #364, then read the planned new module morango/sync/peer.py alongside morango/constants/transfer_stages.py, morango/constants/transfer_statuses.py, and TransferSessionSerializer in morango/api/serializers.py. Add unit tests for both constructors, validation, immutability, equality, Python 3.6 compatibility, and empty counts; done means all listed acceptance criteria pass.

由索引模型根據 Issue 內容生成。

描述

DEV: backend P0 - critical TAG: tech update / debt

Overview

This task (milestone M3) adds PeerTransferSession, an immutable value that describes a transfer session as the peer sees it. The Peer protocol in #370 and #371 returns this value.

Background & Motivation

Today the network operations read raw JSON dictionaries from server responses. The disk connection has no JSON, so operations need a value that does not depend on the transport. A typed value also makes invalid stage and status values fail early, at the connection boundary.

Design: spec. Plan: implementation plan, Task 8.

Description & Expected Outcomes

The value has these fields: id, filter, push, records_total, records_transferred, transfer_stage, transfer_stage_status, server_fsic, and client_fsic. Nobody can change a value after it exists. Two values with the same fields are equal.

A network connection builds the value from server JSON. A disk connection builds it from a TransferSession row. The value rejects an unknown stage or status. An empty record count becomes 0.

Deliverables & Contracts

The task delivers:

  • PeerTransferSession in the new module morango/sync/peer.py.
  • PeerTransferSession.from_api_json(data) and PeerTransferSession.from_model(transfer_session).
Acceptance Criteria
  • from_api_json and from_model give equal values for the same transfer session state.
  • An unknown transfer_stage or transfer_stage_status raises ValueError.
  • A records_total of None becomes 0.
  • An attempt to set an attribute raises AttributeError.
  • The class works on Python 3.6.

Technical Pointers & Architecture

  • Target Components: New module morango/sync/peer.py.
  • Related Patterns: morango/constants/transfer_stages.py and morango/constants/transfer_statuses.py give the valid values. The server JSON shape comes from TransferSessionSerializer in morango/api/serializers.py.
  • Data Model & Schema Considerations: No schema change. The value is not stored.
  • Resilience & Failure Modes: Invalid peer data fails at construction with ValueError.

Notes & Tradeoffs

  • Dependencies: Blocked by: #364 (Tests that pin today's legacy network sync behavior). Blocks: #370, #371.
  • Testing Requirements: Unit tests only.
  • Tradeoffs & Alternatives Considered: Python 3.6 has no dataclasses, so the class uses __slots__ and read-only properties.

Metadata

  • Complexity: Low
  • Target Branch: release-v0.9.x

AI Usage

Drafted with Claude (Claude Code) from the approved design spec and implementation plan. The author reviewed the requirements, and the code references were checked against the release-v0.9.x codebase.

主要語言
Python
星號
15
分支
27
平均合併
6 天 44 分鐘
30 天內合併 PR
13

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

learningequality/morango 的其他 Issue

查看 learningequality/morango 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。