Fix field type detection bug in update_project_item_field (fixes #9)

Ready to merge
MW
1y ago
+482-27

Problem

The update_project_item_field function failed when updating Number and Date fields in GitHub Projects V2. The root cause was incorrect field type detection logic that relied on unreliable field ID prefixes.

Issues Found:

  • Number fields (e.g., "Story Points") with ID PVTF_lAHOAAW1i84BADGgzgy-kZs were incorrectly treated as Text fields
  • Date fields (e.g., "Start Date") with ID PVTF_lAHOAAW1i84BADGgzgy-JI8 were also incorrectly treated as Text fields
  • Both field types have IDs starting with PVTF_, but the code assumed this prefix always indicated Text fields
  • This caused GraphQL mutations with wrong field value types:
    • Number fields got {"text": "64"} instead of {"number": 64.0}
    • Date fields got {"text": "2025-08-11"} instead of {"date": "2025-08-11"}

Solution

Replaced unreliable ID prefix guessing with actual field metadata lookup from GitHub's GraphQL API.

Key Changes:

  1. Enhanced GraphQL query: Added dataType field to get_project_fields_details query
  2. Improved field metadata: Store dataType alongside existing field information
  3. Robust type detection: Use actual field type and dataType instead of ID prefixes:
    • ProjectV2Field with dataType: "NUMBER" → {"number": float(value)}
    • ProjectV2Field with dataType: "DATE" → {"date": value}
    • ProjectV2Field with dataType: "TEXT" → {"text": str(value)}
    • ProjectV2SingleSelectField → {"singleSelectOptionId": value}

Files Modified:

  • src/github_projects_mcp/github_client.py: Core fix implementation
  • pyproject.toml: Added dev dependencies for testing

Test Files Added:

  • test_simple_bug_demo.py: Demonstrates the original bug
  • test_simple_fix.py: Verifies the fix works correctly
  • analysis.md: Detailed root cause analysis and implementation plan
  • github-projects-mcp-issue.md: Bug report with reproduction steps

Testing

  • ✅ Number fields now correctly generate {"number": 64.0}
  • ✅ Date fields now correctly generate {"date": "2025-08-11"}
  • ✅ SingleSelect fields continue to work as before
  • ✅ Comprehensive error handling for invalid field values
  • ✅ Backward compatibility maintained

This fix enables reliable updates of all GitHub Projects V2 field types without depending on unreliable heuristics and fixes #9