fix: template loading - use index-based row access to avoid unpack error
- Changed from dict-style access (proj['type']) to index access (proj[0]) - Added try/except around each row processing to skip bad rows - Added detailed error logging with traceback - Handle cases where row has fewer columns than expected
This commit is contained in:
parent
91a8da3910
commit
5a76c64b2f
|
|
@ -1136,41 +1136,67 @@ class MainWindow(QMainWindow):
|
|||
)
|
||||
|
||||
for proj in projects:
|
||||
# sqlite3.Row doesn't have .get() method
|
||||
proj_type = proj['type'] if 'type' in proj.keys() else 'hunt'
|
||||
activity = ActivityType.from_string(proj_type)
|
||||
# Get session count
|
||||
count_result = self.db.fetchone(
|
||||
"SELECT COUNT(*) as count FROM sessions WHERE project_id = ?",
|
||||
(proj['id'],)
|
||||
)
|
||||
session_count = count_result['count'] if count_result else 0
|
||||
|
||||
# Get last session
|
||||
last_result = self.db.fetchone(
|
||||
"SELECT MAX(started_at) as last FROM sessions WHERE project_id = ?",
|
||||
(proj['id'],)
|
||||
)
|
||||
last_session = None
|
||||
if last_result and last_result['last']:
|
||||
last_session = datetime.fromisoformat(last_result['last'])
|
||||
|
||||
# Handle description which might not exist in old databases
|
||||
description = proj['description'] if 'description' in proj.keys() else ''
|
||||
created_at = proj['created_at'] if 'created_at' in proj.keys() else None
|
||||
|
||||
template = SessionTemplate(
|
||||
id=proj['id'],
|
||||
name=proj['name'],
|
||||
activity_type=activity,
|
||||
description=description,
|
||||
created_at=datetime.fromisoformat(created_at) if created_at else None,
|
||||
session_count=session_count,
|
||||
last_session=last_session
|
||||
)
|
||||
templates.append(template)
|
||||
try:
|
||||
# Access row data by index to avoid key issues
|
||||
proj_id = proj[0] if len(proj) > 0 else 0
|
||||
proj_name = proj[1] if len(proj) > 1 else "Unnamed"
|
||||
proj_type = proj[2] if len(proj) > 2 else 'hunt'
|
||||
proj_created = proj[3] if len(proj) > 3 else None
|
||||
proj_desc = proj[4] if len(proj) > 4 else ''
|
||||
|
||||
activity = ActivityType.from_string(proj_type)
|
||||
|
||||
# Get session count
|
||||
session_count = 0
|
||||
try:
|
||||
count_result = self.db.fetchone(
|
||||
"SELECT COUNT(*) as count FROM sessions WHERE project_id = ?",
|
||||
(proj_id,)
|
||||
)
|
||||
if count_result and len(count_result) > 0:
|
||||
session_count = count_result[0]
|
||||
except:
|
||||
pass
|
||||
|
||||
# Get last session
|
||||
last_session = None
|
||||
try:
|
||||
last_result = self.db.fetchone(
|
||||
"SELECT MAX(started_at) as last FROM sessions WHERE project_id = ?",
|
||||
(proj_id,)
|
||||
)
|
||||
if last_result and len(last_result) > 0 and last_result[0]:
|
||||
last_session = datetime.fromisoformat(last_result[0])
|
||||
except:
|
||||
pass
|
||||
|
||||
# Parse created_at
|
||||
created_at = None
|
||||
if proj_created:
|
||||
try:
|
||||
created_at = datetime.fromisoformat(proj_created)
|
||||
except:
|
||||
pass
|
||||
|
||||
template = SessionTemplate(
|
||||
id=proj_id,
|
||||
name=proj_name,
|
||||
activity_type=activity,
|
||||
description=proj_desc,
|
||||
created_at=created_at,
|
||||
session_count=session_count,
|
||||
last_session=last_session
|
||||
)
|
||||
templates.append(template)
|
||||
|
||||
except Exception as row_error:
|
||||
self.log_warning("Templates", f"Skipping malformed template row: {row_error}")
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
self.log_error("Templates", f"Failed to load templates: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
return templates
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue