Fix fetch_gsoc_orgs command to prevent duplicate organizations and properly track participation years #4602
+258
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The existing
fetch_gsoc_orgsmanagement command had critical issues that would cause duplicate organizations to be created when run multiple times:gsoc_yearsas a Python list attribute (lines 146-152), but this field didn't exist in the Organization model, causing the command to fail silently and potentially create duplicate organizationsorg.gsoc_yearsbut the Organization model lacked this field entirelySolution
This PR implements a complete fix for the GSoC organizations import functionality:
1. Added
gsoc_yearsField to Organization ModelAdded a new
CharFieldto track GSoC participation history:The field stores years as a comma-separated string (e.g., "2024,2023,2022") for simplicity and compatibility.
2. Fixed Duplicate Prevention Logic
The command now properly prevents duplicates through URL-based detection:
3. Proper Year Tracking Implementation
The command now correctly manages participation years:
This ensures:
4. Comprehensive Test Coverage
Added 5 test cases to ensure the command works correctly:
test_fetch_creates_new_organization- Verifies new organization creationtest_fetch_updates_existing_organization- Ensures updates instead of duplicatestest_fetch_prevents_duplicate_years- Tests year deduplicationtest_fetch_sorts_years_descending- Validates year orderingtest_fetch_handles_organization_without_url- Edge case handlingAll tests pass successfully.
Usage
Benefits
Files Changed
website/models.py- Addedgsoc_yearsfield to Organization modelwebsite/management/commands/fetch_gsoc_orgs.py- Fixed duplicate prevention and year trackingwebsite/migrations/0247_organization_gsoc_years.py- Database migration for new fieldwebsite/tests_fetch_gsoc_orgs.py- Comprehensive test suiteCloses #3285
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
esm.ubuntu.com/usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.