Skip to content

Fix campaign collection bug: extract planet_index from nested structure - #13

Merged
surrealwolf merged 12 commits into
mainfrom
fix/campaign-collection-bug
Nov 2, 2025
Merged

surrealwolf merged 12 commits into
mainfrom
fix/campaign-collection-bug

Conversation

@surrealwolf

Copy link
Copy Markdown
Collaborator

Description

Fixes critical bug in campaign data collection where campaigns were never being saved to the database.

Root Cause

The collector was trying to extract planet_index from a top-level field that doesn't exist in the Hell Divers 2 API response. The actual structure has planet data nested inside a planet object with the index inside it.

Changes Made

1. src/collector.py (line 73)

  • Before: planet_index = campaign.get('planet_index') → always returns None
  • After: planet_index = campaign.get('planet', {}).get('index') → correctly extracts nested value

2. src/database.py (line 201)

  • Before: status = data.get("status", "Unknown") → campaigns saved with status='Unknown'
  • After: status = "active" → campaigns correctly marked as active since API only returns active campaigns

Results

  • ✅ 45 campaigns now properly collected and stored in database
  • ✅ All campaigns have correct planet_index values (no more None values)
  • ✅ /api/campaigns/active endpoint now returns campaign data (was returning 404)
  • ✅ All 155 tests pass
  • ✅ No changes to test coverage (82.90%)

Testing

  • Verified database contains 45 campaigns with correct planet indices
  • Tested /api/campaigns returns 45 live campaigns
  • Tested /api/campaigns/active returns 45 active campaigns from database
  • All unit tests still passing

Fixes #[issue-number] (if applicable)

- Fix collector.py: Extract planet_index from nested campaign.planet.index instead of non-existent campaign.planet_index
- Fix database.py: Set campaign status to 'active' since API only returns active campaigns
- Now 45 active campaigns are properly collected and stored
- /api/campaigns/active endpoint now returns data instead of 404
Copilot AI review requested due to automatic review settings October 26, 2025 06:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical bug where campaigns were never being saved to the database due to incorrect planet_index extraction from the nested API response structure.

Key Changes:

  • Fixed planet_index extraction in collector to access nested planet.index field
  • Updated campaign status to hardcode "active" since API only returns active campaigns
  • Refactored database.py with schema improvements and simplified methods

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/collector.py Fixed campaign collection logic to properly extract planet_index from nested structure
src/database.py Updated save_campaign to use hardcoded "active" status and simplified schema/queries

Comment thread src/collector.py Outdated
Comment thread src/collector.py Outdated
Comment thread src/collector.py Outdated
Comment thread src/collector.py Outdated
Copilot AI review requested due to automatic review settings October 26, 2025 06:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/database.py Outdated
Comment thread src/database.py Outdated
Copilot AI review requested due to automatic review settings October 26, 2025 07:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread src/database.py Outdated
Comment thread src/database.py Outdated
Comment thread src/database.py Outdated
Comment thread src/database.py Outdated
Comment thread src/app.py Outdated
Copilot AI review requested due to automatic review settings November 2, 2025 19:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread src/database.py Outdated
Comment thread src/app.py Outdated
Comment thread src/database.py Outdated
Comment thread tests/test_database_coverage.py Outdated
Comment thread tests/test_database_coverage.py
Copilot AI review requested due to automatic review settings November 2, 2025 19:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comment thread src/database.py Outdated
Comment thread src/database.py Outdated
Comment thread src/app.py Outdated
Copilot AI review requested due to automatic review settings November 2, 2025 19:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Comment thread src/database.py
Comment thread src/database.py
Comment thread src/database.py
Comment thread src/app.py
Comment thread src/database.py
@surrealwolf
surrealwolf merged commit b4dc74e into main Nov 2, 2025
14 checks passed
@surrealwolf
surrealwolf deleted the fix/campaign-collection-bug branch November 2, 2025 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants