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:
|
for proj in projects:
|
||||||
# sqlite3.Row doesn't have .get() method
|
try:
|
||||||
proj_type = proj['type'] if 'type' in proj.keys() else 'hunt'
|
# 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)
|
activity = ActivityType.from_string(proj_type)
|
||||||
|
|
||||||
# Get session count
|
# Get session count
|
||||||
|
session_count = 0
|
||||||
|
try:
|
||||||
count_result = self.db.fetchone(
|
count_result = self.db.fetchone(
|
||||||
"SELECT COUNT(*) as count FROM sessions WHERE project_id = ?",
|
"SELECT COUNT(*) as count FROM sessions WHERE project_id = ?",
|
||||||
(proj['id'],)
|
(proj_id,)
|
||||||
)
|
)
|
||||||
session_count = count_result['count'] if count_result else 0
|
if count_result and len(count_result) > 0:
|
||||||
|
session_count = count_result[0]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Get last session
|
# Get last session
|
||||||
|
last_session = None
|
||||||
|
try:
|
||||||
last_result = self.db.fetchone(
|
last_result = self.db.fetchone(
|
||||||
"SELECT MAX(started_at) as last FROM sessions WHERE project_id = ?",
|
"SELECT MAX(started_at) as last FROM sessions WHERE project_id = ?",
|
||||||
(proj['id'],)
|
(proj_id,)
|
||||||
)
|
)
|
||||||
last_session = None
|
if last_result and len(last_result) > 0 and last_result[0]:
|
||||||
if last_result and last_result['last']:
|
last_session = datetime.fromisoformat(last_result[0])
|
||||||
last_session = datetime.fromisoformat(last_result['last'])
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Handle description which might not exist in old databases
|
# Parse created_at
|
||||||
description = proj['description'] if 'description' in proj.keys() else ''
|
created_at = None
|
||||||
created_at = proj['created_at'] if 'created_at' in proj.keys() else None
|
if proj_created:
|
||||||
|
try:
|
||||||
|
created_at = datetime.fromisoformat(proj_created)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
template = SessionTemplate(
|
template = SessionTemplate(
|
||||||
id=proj['id'],
|
id=proj_id,
|
||||||
name=proj['name'],
|
name=proj_name,
|
||||||
activity_type=activity,
|
activity_type=activity,
|
||||||
description=description,
|
description=proj_desc,
|
||||||
created_at=datetime.fromisoformat(created_at) if created_at else None,
|
created_at=created_at,
|
||||||
session_count=session_count,
|
session_count=session_count,
|
||||||
last_session=last_session
|
last_session=last_session
|
||||||
)
|
)
|
||||||
templates.append(template)
|
templates.append(template)
|
||||||
|
|
||||||
|
except Exception as row_error:
|
||||||
|
self.log_warning("Templates", f"Skipping malformed template row: {row_error}")
|
||||||
|
continue
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log_error("Templates", f"Failed to load templates: {e}")
|
self.log_error("Templates", f"Failed to load templates: {e}")
|
||||||
|
import traceback
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
|
||||||
return templates
|
return templates
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue