fix(leads): Add file size validation to CSV import endpoint (LO-079) - #678
fix(leads): Add file size validation to CSV import endpoint (LO-079)#678Lakshayg136 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughAdds configurable CSV upload size limits, rejects oversized files before reading or queuing imports, and tests both rejected oversized uploads and accepted normal-sized uploads. ChangesCSV Upload Limits
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/leads/tests.py (1)
204-220: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert that oversized uploads create no import job.
The endpoint is required to reject the file before queuing or persisting work, but this test only checks the HTTP response. Add an assertion that no
LeadImportJobexists fortoo_large.csv.Suggested assertion
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertIn("File size exceeds the limit", response.data['error']) + self.assertFalse( + LeadImportJob.objects.filter( + organization=self.org_a, + filename="too_large.csv", + ).exists() + )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/leads/tests.py` around lines 204 - 220, Extend test_import_csv_oversized_file_rejected to assert that no LeadImportJob exists for the rejected “too_large.csv” upload after the response is returned, while preserving the existing status and error-message assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@backend/leads/tests.py`:
- Around line 204-220: Extend test_import_csv_oversized_file_rejected to assert
that no LeadImportJob exists for the rejected “too_large.csv” upload after the
response is returned, while preserving the existing status and error-message
assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f8b4bb43-af05-41d4-98ea-691722cc8cd9
📒 Files selected for processing (4)
backend/backend/settings.pybackend/config/settings.pybackend/leads/tests.pybackend/leads/views.py
|
please review, add the gssoc Labels and merge it |
Pull Request
🔗 Related Issue
Closes #327
📝 Summary of Changes
MAX_CSV_UPLOAD_SIZEsetting tobackend/backend/settings.py(defaulting to 10MB) to configure the maximum allowable size for uploaded CSV files.import_csvinbackend/leads/views.pyto checkfile_obj.sizeagainstMAX_CSV_UPLOAD_SIZEbefore reading the file. If the file is oversized, it returns a400 Bad Requestresponse, preventing memory exhaustion.test_import_csv_oversized_file_rejectedandtest_import_csv_normal_size_file_acceptedtests tobackend/leads/tests.pyto verify this behavior.🏷️ Type of Change
🧪 Testing
The changes were verified locally using the backend test suite.
Steps to test:
backenddirectory.python manage.py test leads📸 Screenshots (if applicable)
N/A (Backend logic changes only)
✅ Checklist
Summary by CodeRabbit
New Features
Bug Fixes
Tests