[PR #47] [MERGED] Fix JSON serialization of Path objects in CodeQLWorkflowResult #50

Closed
opened 2026-03-02 04:08:02 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/gadievron/raptor/pull/47
Author: @gadievron
Created: 12/22/2025
Status: Merged
Merged: 12/26/2025
Merged by: @danielcuthbert

Base: mainHead: fix/bug-41-json-serialization


📝 Commits (1)

  • 1de8b0e Fix JSON serialization of Path objects in CodeQLWorkflowResult

📊 Changes

1 file changed (+42 additions, -2 deletions)

View changed files

📝 packages/codeql/agent.py (+42 -2)

📄 Description

Summary

Fixes TypeError during autonomous_summary.json generation by properly converting all Path objects to strings in CodeQLWorkflowResult.to_dict(), enabling successful autonomous analysis completion.

Problem

Autonomous analysis workflow fails at final step when attempting to serialize CodeQLWorkflowResult to JSON. The error occurs because to_dict() uses asdict() which doesn't convert pathlib.Path objects to strings, causing TypeError: Object of type PosixPath is not JSON serializable.

Root Cause

The to_dict() method in CodeQLWorkflowResult (agent.py:46-59) manually converts languages_detected but relies on asdict() for everything else. Python's asdict() recursively converts dataclasses but does NOT convert non-dataclass types like Path, datetime, etc.

Affected Path objects (4 total):

  1. databases_created[lang].database_path (Optional[Path])
  2. analyses_completed[lang].database_path (Path)
  3. analyses_completed[lang].sarif_path (Optional[Path])
  4. sarif_files (List[Path]) - Type annotation incorrectly claims List[str]

Changes

File: packages/codeql/agent.py

Method: CodeQLWorkflowResult.to_dict() (lines 46-99)

Extended existing method to manually convert all Path objects:

  • Convert DatabaseResult objects (database_path: Path → str)
  • Convert QueryResult objects (database_path and sarif_path: Path → str)
  • Convert sarif_files list (handles both Path and str)
  • Added documentation for maintaining JSON serializability

Why This Fix is Correct

Location

  • Centralized: Single point of change (to_dict() method)
  • Follows pattern: Same approach as existing languages_detected conversion
  • Clear intent: Explicit about what's being converted and why

Approach

  • Industry standard: Django, SQLAlchemy, Pydantic all convert in to_dict()
  • Preserves internal APIs: Path objects still used internally for type safety
  • Handles edge cases: Properly handles Optional[Path] with None values
  • Defensive: sarif_files uses isinstance() check to handle both Path and str

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Impact

  • Risk: Low - Isolated change, no dependencies affected
  • Scope: JSON serialization only
  • Breaking: No - Only affects output format, not internal APIs

Fixes #41


Note

Ensures workflow results are JSON-serializable by explicitly converting Path fields to strings during report generation.

  • Extends CodeQLWorkflowResult.to_dict() to serialize Path fields in databases_created (database_path), analyses_completed (database_path, sarif_path), and sarif_files (handles Path or str)
  • Preserves existing languages_detected mapping; propagates metadata.to_dict() where present
  • Adds docstring guidance to update to_dict() when introducing non-serializable types

Written by Cursor Bugbot for commit 1de8b0e3f3. This will update automatically on new commits. Configure here.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/gadievron/raptor/pull/47 **Author:** [@gadievron](https://github.com/gadievron) **Created:** 12/22/2025 **Status:** ✅ Merged **Merged:** 12/26/2025 **Merged by:** [@danielcuthbert](https://github.com/danielcuthbert) **Base:** `main` ← **Head:** `fix/bug-41-json-serialization` --- ### 📝 Commits (1) - [`1de8b0e`](https://github.com/gadievron/raptor/commit/1de8b0e3f380aba940a66173fcb64c8bf84b6ff6) Fix JSON serialization of Path objects in CodeQLWorkflowResult ### 📊 Changes **1 file changed** (+42 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/codeql/agent.py` (+42 -2) </details> ### 📄 Description ## Summary Fixes TypeError during autonomous_summary.json generation by properly converting all Path objects to strings in CodeQLWorkflowResult.to_dict(), enabling successful autonomous analysis completion. ## Problem Autonomous analysis workflow fails at final step when attempting to serialize `CodeQLWorkflowResult` to JSON. The error occurs because `to_dict()` uses `asdict()` which doesn't convert `pathlib.Path` objects to strings, causing `TypeError: Object of type PosixPath is not JSON serializable`. ## Root Cause The `to_dict()` method in `CodeQLWorkflowResult` (agent.py:46-59) manually converts `languages_detected` but relies on `asdict()` for everything else. Python's `asdict()` recursively converts dataclasses but **does NOT convert non-dataclass types** like `Path`, `datetime`, etc. **Affected Path objects (4 total):** 1. `databases_created[lang].database_path` (Optional[Path]) 2. `analyses_completed[lang].database_path` (Path) 3. `analyses_completed[lang].sarif_path` (Optional[Path]) 4. `sarif_files` (List[Path]) - Type annotation incorrectly claims List[str] ## Changes ### File: `packages/codeql/agent.py` **Method:** `CodeQLWorkflowResult.to_dict()` (lines 46-99) Extended existing method to manually convert all Path objects: - Convert DatabaseResult objects (database_path: Path → str) - Convert QueryResult objects (database_path and sarif_path: Path → str) - Convert sarif_files list (handles both Path and str) - Added documentation for maintaining JSON serializability ## Why This Fix is Correct ### Location ✅ - **Centralized:** Single point of change (to_dict() method) - **Follows pattern:** Same approach as existing languages_detected conversion - **Clear intent:** Explicit about what's being converted and why ### Approach ✅ - **Industry standard:** Django, SQLAlchemy, Pydantic all convert in to_dict() - **Preserves internal APIs:** Path objects still used internally for type safety - **Handles edge cases:** Properly handles Optional[Path] with None values - **Defensive:** sarif_files uses isinstance() check to handle both Path and str ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) ## Impact - **Risk:** Low - Isolated change, no dependencies affected - **Scope:** JSON serialization only - **Breaking:** No - Only affects output format, not internal APIs Fixes #41 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Ensures workflow results are JSON-serializable by explicitly converting Path fields to strings during report generation. > > - Extends `CodeQLWorkflowResult.to_dict()` to serialize `Path` fields in `databases_created` (`database_path`), `analyses_completed` (`database_path`, `sarif_path`), and `sarif_files` (handles `Path` or `str`) > - Preserves existing `languages_detected` mapping; propagates `metadata.to_dict()` where present > - Adds docstring guidance to update `to_dict()` when introducing non-serializable types > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1de8b0e3f380aba940a66173fcb64c8bf84b6ff6. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 04:08:02 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/raptor#50
No description provided.