refactor: support multi-view project API with legacy project backward compatibility#1700
Open
SAKURA-CAT wants to merge 8 commits into
Open
refactor: support multi-view project API with legacy project backward compatibility#1700SAKURA-CAT wants to merge 8 commits into
SAKURA-CAT wants to merge 8 commits into
Conversation
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.
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.
Summary
为支持多视图功能,对项目创建和列上传接口进行重构,同时保持对旧版本项目的向下兼容。
Changes
项目 API 重构
POST /api/project迁移到POST /api/projects/{username},移除 payload 中的username字段group.username、可选version字段/api/project接口,旧项目可使用到 v0.10.0列上传接口重构
POST /experiment/{id}/columns迁移到POST /projects/{username}/{project}/series{key, type, sectionName},去掉冗余字段旧版兼容逻辑
swanlab/deprecated/project.py和swanlab/deprecated/sender.pyTransport.start()根据项目版本自动选择HttpRecordSender(新版)或DeprecatedHttpRecordSender(旧版)DeprecationWarning改为FutureWarningHTTP Client 改进
Client/SessionWithRetry新增 per-requestlog_error参数,替代对/api/projectURL 的硬编码特判Client登录时缓存username,新增username属性和模块级username()代理函数类型定义
ProjectType新增group._ProjectGroup和可选version字段InitProjectTypeUploadColumn(新版)和DeprecatedUploadColumn(旧版)Testing
已执行:
uv run pytest tests/unit/sdk/internal/core_python/api/test_project.py— 5 passeduv run pytest tests/unit/sdk/internal/core_python/transport/test_sender.py— 11 passeduv run ruff check— 相关文件通过git diff --check— 无空白问题未运行:完整测试套件、basedpyright 类型检查。
Notes
encode_column新 DTO 去除了name、yRange、chartName、metricName等字段,需确认新版后端不再依赖这些字段prepare_experiment_start()通过project_data["group"]["username"]获取用户名,旧后端需保证返回group字段