Fix tiny issues (#14006)

### What problem does this PR solve?

As title

### Type of change

- [x] Refactoring



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Improved authentication error logging to better distinguish between
JWT and API token failures.
* Enhanced code documentation with clarifying comments for better
maintainability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-04-09 19:01:36 +08:00
committed by GitHub
parent 3c5a3e5fb4
commit e2b879b258
2 changed files with 12 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ from peewee import DoesNotExist
class UserCanvasVersionService(CommonService):
model = UserCanvasVersion
# Build a stable display name for saved snapshots.
@staticmethod
def build_version_title(user_nickname, agent_title, ts=None):
tenant = str(user_nickname or "").strip() or "tenant"
@@ -18,6 +19,7 @@ class UserCanvasVersionService(CommonService):
stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts)) if ts is not None else time.strftime("%Y-%m-%d %H:%M:%S")
return "{0}_{1}_{2}".format(tenant, title, stamp)
# Normalize DSL before comparing or writing version content.
@staticmethod
def _normalize_dsl(dsl):
normalized = dsl
@@ -143,6 +145,7 @@ class UserCanvasVersionService(CommonService):
.first()
)
# Repeated saves with the same DSL only refresh the latest snapshot.
if latest and cls._normalize_dsl(latest.dsl) == normalized_dsl:
# Protect released version: if latest is released and current is not,
# create a new version instead of updating
@@ -170,6 +173,7 @@ class UserCanvasVersionService(CommonService):
cls.delete_all_versions(user_canvas_id)
return latest.id, False
# Real content changes create a new snapshot.
insert_data = {"user_canvas_id": user_canvas_id, "dsl": normalized_dsl}
if title is not None:
insert_data["title"] = title