Skip to content

Fix: PATCH endpoint replacing resources instead of adding them#93

Merged
rbardaji merged 3 commits intomainfrom
fix/patch-resources-not-adding-issue-92
Jul 3, 2025
Merged

Fix: PATCH endpoint replacing resources instead of adding them#93
rbardaji merged 3 commits intomainfrom
fix/patch-resources-not-adding-issue-92

Conversation

@rbardaji
Copy link
Copy Markdown
Collaborator

@rbardaji rbardaji commented Jul 3, 2025

PATCH /dataset/{id} was replacing all existing resources instead of adding new ones, making it behave identically to PUT.

Before: PATCH replaced all resources (incorrect)
After: PATCH adds new resources to existing ones (correct)

Fixes #92

Changes

  • Modified patch_general_dataset() in api/services/dataset_services/general_dataset.py
  • Resources are now merged instead of replaced during PATCH operations
  • Existing resources are preserved and new ones are added
  • PUT behavior unchanged (still replaces all resources)

Testing

Reproduction Test Results

# Before fix
Initial resources: 1 → Final resources: 1 ❌ (replaced)

# After fix  
Initial resources: 1 → Final resources: 2 ✅ (added)

Verification

  • PATCH adds resources without removing existing ones
  • PATCH updates existing resources by URL/name matching
  • PUT behavior unchanged
  • No regression in other dataset fields
  • Manual API testing completed

API Behavior

PATCH /dataset/{id} (Fixed)

{
  "resources": [{"url": "new.json", "name": "new_resource"}]
}

Result: Adds to existing resources ✅

PUT /dataset/{id} (Unchanged)

{
  "resources": [{"url": "replacement.csv", "name": "replacement"}]
}

Result: Replaces all resources ✅

Review Checklist

  • Reproduction script confirms bug existed
  • Fix verified with enhanced test script
  • No breaking changes (fixes incorrect behavior)
  • Maintains backward compatibility
  • Code follows existing conventions

rbardaji added 3 commits July 3, 2025 17:58
Add test script that confirms PATCH /dataset/{id} endpoint replaces
existing resources instead of adding new ones.

- Creates test organization and dataset automatically
- Demonstrates the bug: PATCH replaces all resources like PUT
- Includes cleanup of test data
- Script exits with code 1 when issue is confirmed

Related to #92
Add modified patch_general_dataset() function that adds resources
instead of replacing them. Fix needs verification and testing.

- Changes resource handling logic to preserve existing resources
- Adds new resources to existing list instead of replacing
- Updates existing resources by URL or name matching
- Implementation ready for testing and validation

Related to #92
Created test_patch_resources_issue_fixed.py that confirms the fix works correctly.
PATCH /dataset/{id} now properly adds resources instead of replacing them.

- Enhanced test script with better organization handling
- Confirms fix resolves issue #92
- PATCH now preserves existing resources and adds new ones
- Test shows resource count increases as expected

Verifies fix for #92
@rbardaji rbardaji merged commit 8f49200 into main Jul 3, 2025
2 checks passed
@rbardaji rbardaji deleted the fix/patch-resources-not-adding-issue-92 branch July 3, 2025 16:25
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.

patch is not accepting resources

1 participant