Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Fix ASR empty text validation and add cascade delete for recording relationships
Murtaza Nasir337297828c4b
diff --git a/src/models/audit.py b/src/models/audit.pyindex ad24d098..beeceddb 100644--- a/src/models/audit.py+++ b/src/models/audit.py@@ -17,7 +17,7 @@ class ShareAuditLog(db.Model):# Action detailsaction = db.Column(db.String(20), nullable=False) # 'created', 'modified', 'revoked', 'cascade_revoked'- recording_id = db.Column(db.Integer, db.ForeignKey('recording.id'), nullable=False)+ recording_id = db.Column(db.Integer, db.ForeignKey('recording.id', ondelete='CASCADE'), nullable=False)# Actor (who performed the action)actor_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)@@ -40,7 +40,7 @@ class ShareAuditLog(db.Model):ip_address = db.Column(db.String(45), nullable=True) # Actor's IP address# Recording relationship- recording = db.relationship('Recording', backref='share_audit_logs')+ recording = db.relationship('Recording', backref=db.backref('share_audit_logs', cascade='all, delete-orphan'))def to_dict(self):"""Convert to dictionary for API responses."""diff --git a/src/models/processing_job.py b/src/models/processing_job.pyindex c8bdc09a..375e1cd6 100644--- a/src/models/processing_job.py+++ b/src/models/processing_job.py@@ -16,7 +16,7 @@ class ProcessingJob(db.Model):id = db.Column(db.Integer, primary_key=True)user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False, index=True)- recording_id = db.Column(db.Integer, db.ForeignKey('recording.id'), nullable=False, index=True)+ recording_id = db.Column(db.Integer, db.ForeignKey('recording.id', ondelete='CASCADE'), nullable=False, index=True)# Job type: transcribe, summarize, reprocess_transcription, reprocess_summaryjob_type = db.Column(db.String(50), nullable=False)@@ -41,7 +41,7 @@ class ProcessingJob(db.Model):# Relationshipsuser = db.relationship('User', backref=db.backref('processing_jobs', lazy='dynamic'))- recording = db.relationship('Recording', backref=db.backref('processing_jobs', lazy='dynamic'))+ recording = db.relationship('Recording', backref=db.backref('processing_jobs', lazy='dynamic', cascade='all, delete-orphan'))def __repr__(self):return f'<ProcessingJob {self.id} type={self.job_type} status={self.status}>'diff --git a/src/services/transcription/connectors/asr_endpoint.py b/src/services/transcription/connectors/asr_endpoint.pyindex 975c760f..89954c48 100644--- a/src/services/transcription/connectors/asr_endpoint.py+++ b/src/services/transcription/connectors/asr_endpoint.py@@ -213,7 +213,7 @@ class ASREndpointConnector(BaseTranscriptionConnector):))# Get the full text- if 'text' in data:+ if 'text' in data and isinstance(data['text'], str):full_text = data['text']elif full_text_parts:full_text = '\n'.join(full_text_parts)diff --git a/src/tasks/processing.py b/src/tasks/processing.pyindex 0f4599f7..c44d43e5 100644--- a/src/tasks/processing.py+++ b/src/tasks/processing.py@@ -1555,9 +1555,10 @@ def transcribe_with_connector(app_context, recording_id, filepath, original_filerecording.transcription = response.to_storage_format()current_app.logger.info(f"Transcription completed with {len(response.segments)} segments and {len(response.speakers or [])} speakers")else:- # Store as plain text- recording.transcription = response.text- current_app.logger.info(f"Transcription completed: {len(response.text)} characters")+ # Store as plain text (ensure it's a string)+ transcription_text = response.text if isinstance(response.text, str) else ''+ recording.transcription = transcription_text+ current_app.logger.info(f"Transcription completed: {len(transcription_text)} characters")# Store speaker embeddings if availableif response.speaker_embeddings: