Skip to content

fix: temp files are always cleaned after upload success or failure (T415717)#81

Open
ryaverma wants to merge 1 commit into
indictechcom:masterfrom
ryaverma:fix/temp-file-cleanup
Open

fix: temp files are always cleaned after upload success or failure (T415717)#81
ryaverma wants to merge 1 commit into
indictechcom:masterfrom
ryaverma:fix/temp-file-cleanup

Conversation

@ryaverma
Copy link
Copy Markdown

Description

Temporary files created during uploads were never cleaned up after success/failure. This causes files accumulating in temp_images/ directory.

Issue

Closes T415717

What This PR Does

utils.py

  1. Added cleanup_temp_file() function for file removal with logging
  2. Added get_headers() for consistent User-Agent headers on all API requests
  3. Cleans up partial downloads if download_image() fails midway
  4. Uses context managers for all file operations
  5. Added proper error handling and logging throughout

tasks.py

  1. Imported cleanup_temp_file and get_headers from utils
  2. Added finally block to guarantee temp file cleanup after Celery task completes/succeeds/fails
  3. Added request timeouts and error handling

app.py

  1. Updated import to use get_headers and cleanup_temp_file from utils
  2. Added finally block in synchronous upload path
  3. Added input validation with error messages
  4. Added exception handling
  5. Partial downloads failing midway are cleaned up
  6. cleanup_temp_file() is used with logging across all files instead of os.remove() call

Testing

Verified all three files import correctly with no errors.

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.

1 participant