Openleaf
Returns & Exchanges for Modern D2C Brands
Created on 15th February 2026
•
Openleaf
Returns & Exchanges for Modern D2C Brands
The problem Openleaf solves
When people buy products from brand websites, returning or exchanging an
item is o en slow and frustra ng. Customers usually have to fill long forms and
wait for approvals. At the same me, brands spend a lot of me manually
checking return requests, handling fake or damaged returns, and coordina ng
pickups. Because of this, brands lose money, waste inventory, and somemes
issue refunds even when a simple exchange would have been a be er op on
for both sides.
Problem Outcomes:
The challenge is to re-imagine how returns and exchanges should work today if
they were built from scratch using modern technology.
Think about how the experience can be faster, smarter, and more seamless for
both buyers and brands - reducing manual effort, avoiding unnecessary
refunds, and helping brands save revenue while keeping customers happy.
Challenges we ran into
- Media URL Resolution (404 Errors)
Problem: When clicking on delivery or unboxing photo buttons, the images returned 404 errors. The frontend was trying to access media from localhost:3000 instead of the backend at localhost:8000.
Solution: Created a getMediaUrl() helper function in utils.ts that converts relative URLs to absolute backend URLs using the API_BASE_URL constant. This ensured all media requests were properly directed to the backend server's static file serving endpoint.
- TypeScript Type Safety Issues
Problem: Filter arrays with undefined values caused TypeScript errors: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Solution: Added explicit return type annotations (: string[]) to useMemo hooks and used type assertions to ensure TypeScript recognized the filtered arrays as non-nullable string arrays.
- BLOB Storage Architecture Problems
Problem: Storing media files as BLOBs in the database caused multiple issues:
Inefficient for web applications
Complex URL resolution
Database bloat with binary data
The critical "no such column: file_data" error after schema changes
Solution: Migrated from BLOB storage to file system storage:
Updated schema.sql to remove the file_data BLOB column
Modified upload endpoints to save files to uploads/claims/{claim_id}/ directories
Created migration scripts to extract existing BLOB data to files (9 records migrated)
Updated AI model to read from file paths instead of BLOB data:
4. AI Model Integration with New Storage System
Problem: After migrating to file system storage, the AI claim processor failed with "AI processing failed: no such column: file_data" because it was still trying to query the removed BLOB column.
Solution: Updated ai_claim_processor.py to:
Query media_url instead of file_data
Construct proper file paths using the base upload directory
Use load_image_from_path() instead of load_image_from_bytes()
Added error handling for missing files
Key Takeaways
File system storage is more scalable and maintainable than BLOB storage for web applications
Helper functions (like getMediaUrl()) centralize logic and prevent duplication
Type safety in TypeScript requires explicit annotations when TypeScript can't infer types
Migration planning is crucial when changing fundamental data storage patterns