diff --git a/python_core/database/template_postgres.py b/python_core/database/template_postgres.py index 9b48aa0..8e245c8 100644 --- a/python_core/database/template_postgres.py +++ b/python_core/database/template_postgres.py @@ -159,8 +159,12 @@ PostgreSQL 驱动 psycopg2 未安装。请安装: now = datetime.now() - # 处理 draft_content,如果 template_info 有 draft_content 属性则使用,否则为空对象 - draft_content = getattr(template_info, 'draft_content', {}) + # 处理 draft_content + draft_content = template_info.draft_content + if draft_content is None: + draft_content = {} + + logger.debug(f"Storing draft_content for template {template_id}: {type(draft_content)} with {len(draft_content)} keys") cursor.execute(insert_sql, ( template_id, diff --git a/python_core/database/types.py b/python_core/database/types.py index 5663eda..e701177 100644 --- a/python_core/database/types.py +++ b/python_core/database/types.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import Dict, List, Any, Optional @@ -55,4 +55,4 @@ class TemplateInfo: # 创建用户 user_id: str = "" # draft content 存储在数据库中的内容 - draft_content: Dict[str, Any] = None \ No newline at end of file + draft_content: Dict[str, Any] = field(default_factory=dict) \ No newline at end of file diff --git a/python_core/services/template_manager.py b/python_core/services/template_manager.py index b1d36de..91cd033 100644 --- a/python_core/services/template_manager.py +++ b/python_core/services/template_manager.py @@ -252,7 +252,8 @@ class TemplateManager: duration=draft_content.get('duration', 0), material_count=len(materials), track_count=len(draft_content.get('tracks', [])), - tags=[] + tags=[], + draft_content=draft_content # 设置 draft_content ) # Save to metadata diff --git a/python_core/services/template_manager_cloud.py b/python_core/services/template_manager_cloud.py index 24b1f11..fab3075 100644 --- a/python_core/services/template_manager_cloud.py +++ b/python_core/services/template_manager_cloud.py @@ -214,7 +214,8 @@ class TemplateManagerCloud: track_count=len(draft_content.get('tracks', [])), tags=[], is_cloud=False, # 用户导入的模板默认为本地 - user_id=self.user_id + user_id=self.user_id, + draft_content=updated_draft # 设置 draft_content ) logger.info(f"Successfully processed template: {template_name} -> {template_id}") @@ -531,7 +532,8 @@ class TemplateManagerCloud: track_count=len(draft_content.get('tracks', [])), tags=tags or [], is_cloud=is_cloud, - user_id=self.user_id + user_id=self.user_id, + draft_content=draft_content # 设置 draft_content ) # 保存到云端存储