Skip to content

Comments

Fix/upload#1381

Merged
SAKURA-CAT merged 5 commits intomainfrom
fix/upload
Dec 19, 2025
Merged

Fix/upload#1381
SAKURA-CAT merged 5 commits intomainfrom
fix/upload

Conversation

@SAKURA-CAT
Copy link
Member

Description

  1. 在指标等信息上传层面添加了空数组校验
  2. 修复上传Text指标时出现的后端报错400问题,原因是Text指标本身没有媒体资源,导致签名请求体为空

Closes: #1379

Added early return statements to uploader functions in upload.py to handle empty input lists, preventing unnecessary processing and logging debug messages. Also updated comments and TODOs for consistency in batch.py and upload.py.
Introduced a skip_if_empty decorator to reduce code duplication by handling empty input lists for upload functions. This change improves code readability and maintainability by centralizing the empty-check logic and debug logging.
@SAKURA-CAT SAKURA-CAT requested a review from Zeyi-Lin December 18, 2025 14:34
@SAKURA-CAT SAKURA-CAT self-assigned this Dec 18, 2025
@SAKURA-CAT SAKURA-CAT added the 🐛 bug Something isn't working label Dec 18, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SAKURA-CAT, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness and correctness of the data upload mechanisms within the system. It introduces a new validation layer to efficiently handle empty data arrays, preventing redundant upload calls. A specific fix addresses a backend error encountered when uploading Text metrics by ensuring that media resource uploads are only attempted when actual media buffers exist. Additionally, the PR includes routine updates to IDE-specific configuration files.

Highlights

  • Empty Array Validation: A new decorator, skip_if_empty, has been implemented and applied to various upload functions (e.g., upload_logs, upload_media_metrics, upload_scalar_metrics). This decorator prevents upload attempts when the input data list is empty, logging a debug message instead of proceeding with an unnecessary request.
  • Text Metric Upload Fix: The upload_media_metrics function has been refined to correctly handle Text metrics, which inherently lack media resources. The upload_to_cos call is now conditionally executed only if media buffers are present, resolving a previous backend error (400) that occurred due to an empty signature request body for Text metrics.
  • IDE Configuration Updates: Minor adjustments have been made to .idea/ configuration files, including updates to Python documentation settings, the project dictionary (adding 'projname'), and the default inspection profiles for Python code.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

你好,感谢你对代码的改进。这次的 Pull Request 主要通过引入 @skip_if_empty 装饰器,统一了上传函数对于空数据列表的处理逻辑,并修复了上传 Text 指标时因媒体资源为空导致的 400 错误,这些都是很好的优化。

代码整体实现不错,我提出了一些具体的建议,主要集中在 swanlab/core_python/uploader/upload.py 文件中,旨在提高代码的可读性和健壮性。请查看我的具体评论。

Simplified and unified empty list checks by removing redundant length checks in upload_files and upload_columns, and improving logic in skip_if_empty and upload_media_metrics. This streamlines the code and relies on existing mechanisms for handling empty inputs.
@SAKURA-CAT
Copy link
Member Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 主要通过引入 skip_if_empty 装饰器,统一了在上传各种指标前对空数组的校验逻辑,并移除了原有的重复代码,提高了代码的复用性。同时,修复了 upload_media_metrics 函数中因 Text 指标没有媒体资源而导致请求体为空的400错误。

整体来看,代码变更清晰地解决了所述问题。我对新引入的装饰器提出了一点改进建议,旨在增强其健壮性和未来可维护性。除此之外,其他修改均合理有效。

Refactored the skip_if_empty decorator to use inspect for more robust detection of the first parameter, supporting both positional and keyword arguments. This ensures the decorator works correctly regardless of how the decorated function is called.
@SAKURA-CAT
Copy link
Member Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

此PR引入了"skip_if_empty"装饰器,用于在上传数据前集中检查空列表,这提高了代码的整洁性并避免了不必要的API调用。同时,它修复了上传Text指标时因缺少媒体资源导致后端报错400的问题。此外,IDE配置文件也进行了更新,包括新的Python检查设置。

@Zeyi-Lin
Copy link
Member

这个.idea目录是有意义的吗?

@SAKURA-CAT
Copy link
Member Author

这个.idea目录是有意义的吗?

有意义,pycharm开发应该有点用

@SAKURA-CAT SAKURA-CAT merged commit eab4afd into main Dec 19, 2025
5 checks passed
@SAKURA-CAT SAKURA-CAT deleted the fix/upload branch December 19, 2025 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

swanlab: swanlab api error ('Trace id: mj8hheoq8fb86zaj', 'POST https://api.swanlab.cn/api/resources/presigned/put', '400 Bad Request')

2 participants