Skip to content

refactor: support multi-view project API with legacy project backward compatibility#1700

Open
SAKURA-CAT wants to merge 8 commits into
mainfrom
feature/views
Open

refactor: support multi-view project API with legacy project backward compatibility#1700
SAKURA-CAT wants to merge 8 commits into
mainfrom
feature/views

Conversation

@SAKURA-CAT

@SAKURA-CAT SAKURA-CAT commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

为支持多视图功能,对项目创建和列上传接口进行重构,同时保持对旧版本项目的向下兼容。

对多视图功能的支持为 v0.9.0 版本的必要功能

Changes

项目 API 重构

  • 项目创建从 POST /api/project 迁移到 POST /api/projects/{username},移除 payload 中的 username 字段
  • 项目详情接口响应新增 group.username、可选 version 字段
  • 新版接口不可用(404)时自动 fallback 到旧 /api/project 接口,旧项目可使用到 v0.10.0

列上传接口重构

  • 列上传端点从 POST /experiment/{id}/columns 迁移到 POST /projects/{username}/{project}/series
  • 新版列 DTO 简化为 {key, type, sectionName},去掉冗余字段
  • 修复 column 分批上传时变量重绑定导致超 3000 条时尾批次丢失的 bug

旧版兼容逻辑

  • 旧项目创建/列上传逻辑迁移到 swanlab/deprecated/project.pyswanlab/deprecated/sender.py
  • Transport.start() 根据项目版本自动选择 HttpRecordSender(新版)或 DeprecatedHttpRecordSender(旧版)
  • deprecated 警告从 DeprecationWarning 改为 FutureWarning

HTTP Client 改进

  • Client/SessionWithRetry 新增 per-request log_error 参数,替代对 /api/project URL 的硬编码特判
  • Client 登录时缓存 username,新增 username 属性和模块级 username() 代理函数

类型定义

  • ProjectType 新增 group._ProjectGroup 和可选 version 字段
  • 移除 InitProjectType
  • Column DTO 拆分为 UploadColumn(新版)和 DeprecatedUploadColumn(旧版)

Testing

已执行:

  • uv run pytest tests/unit/sdk/internal/core_python/api/test_project.py — 5 passed
  • uv run pytest tests/unit/sdk/internal/core_python/transport/test_sender.py — 11 passed
  • uv run ruff check — 相关文件通过
  • git diff --check — 无空白问题

未运行:完整测试套件、basedpyright 类型检查。

Notes

  • 旧版兼容逻辑计划在 v0.10.0(2026-10-01)后移除
  • encode_column 新 DTO 去除了 nameyRangechartNamemetricName 等字段,需确认新版后端不再依赖这些字段
  • 旧项目的 prepare_experiment_start() 通过 project_data["group"]["username"] 获取用户名,旧后端需保证返回 group 字段

Replace the hardcoded URL-based suppression of error logging for
`/api/project` with a per-request `log_error` flag, defaulting to
`True`. This allows callers to suppress error logs for specific
requests without relying on fragile URL pattern matching.
Restructure the `get_or_create_project` API to try the new endpoint
first and fall back to the legacy one, returning project data directly.
Update column upload to use the new multi-view endpoint
Extract `get_or_create_old_project` and `DeprecatedHttpRecordSender`
into
a dedicated `swanlab/deprecated` module and update all imports.  Add
`@deprecated` decorators and a `DeprecationWarning` to both items.
Fix the login mock in unit tests to include the `userInfo` field.
Update project API to use nested `group` dict for username, deprecate
old
`/api/project` endpoint, and change deprecated warnings from
`DeprecationWarning` to `FutureWarning`. Add legacy project migration
fallback for new endpoint failures, along with comprehensive tests.
Add `make_login_resp` to reduce duplication and add `group` field to
project detail responses
project endpoint

The upload_column method was reusing the name `columns` for the batch
slice,
masking the original parameter and causing later batches to be lost.
Also corrected the project-creation fallback so a server responding with
404
triggers the old endpoint instead of raising an error.
@SAKURA-CAT SAKURA-CAT added 💪 enhancement New feature or request 🔌 api SwanLab OpenAPI labels Jul 7, 2026
@SAKURA-CAT SAKURA-CAT self-assigned this Jul 7, 2026
@SAKURA-CAT SAKURA-CAT requested a review from Nexisato July 7, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔌 api SwanLab OpenAPI 💪 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant