The backend was failing to start with the error:
sqlalchemy.exc.InvalidRequestError: Attribute name 'metadata' is reserved when using the Declarative API.
In the PDFDocument model, we added a column named metadata to store PDF metadata. However, metadata is a reserved attribute in SQLAlchemy's Declarative API used internally by the ORM.
Renamed the database column from metadata to pdf_metadata throughout the codebase.
-
PDFDocument Model (Line 82)
- Changed:
metadata = db.Column(db.JSON) - To:
pdf_metadata = db.Column(db.JSON)
- Changed:
-
PDFDocument.to_dict() Method (Line 95)
- Changed:
'metadata': self.metadata - To:
'metadata': self.pdf_metadata - Note: API still returns
metadatakey for consistency
- Changed:
-
upload_pdf() Function (Line 206)
- Changed:
metadata=pdf_info.get('metadata') - To:
pdf_metadata=pdf_info.get('metadata')
- Changed:
-
merge_pdfs() Function (Line 357)
- Changed:
metadata=pdf_info.get('metadata') - To:
pdf_metadata=pdf_info.get('metadata')
- Changed:
-
split_pdf() Function (Line 438)
- Changed:
metadata=pdf_info.get('metadata') - To:
pdf_metadata=pdf_info.get('metadata')
- Changed:
-
rotate_pdf() Function (Line 523)
- Changed:
metadata=pdf_info.get('metadata') - To:
pdf_metadata=pdf_info.get('metadata')
- Changed:
-
update_document() Function (Line 656)
- Changed:
document.metadata = data['metadata'] - To:
document.pdf_metadata = data['metadata']
- Changed:
The API remains unchanged. The to_dict() method still returns the key as metadata in JSON responses, so no frontend changes are required.
If you have existing data, you'll need to run a migration to rename the column:
ALTER TABLE pdf_documents RENAME COLUMN metadata TO pdf_metadata;Or drop and recreate the database (if no production data):
docker-compose down -v
docker-compose up -dAfter applying this fix:
- Restart the backend:
docker-compose restart backend celery_worker - Verify services start without errors:
docker-compose logs backend - Test upload endpoint:
curl -X POST http://localhost:5000/api/upload -F "file=@test.pdf" - Verify metadata is returned correctly in API responses
✅ Fixed - All references to metadata column updated to pdf_metadata