Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Recording titles cut to the 200-character column wherever they are set

Murtaza Nasirec75e6deb730
diff --git a/src/models/recording.py b/src/models/recording.py
index 1583c70a..ba3f82b9 100644
--- a/src/models/recording.py
+++ b/src/models/recording.py
@@ -8,6 +8,7 @@ import logging
import os
from datetime import datetime
from sqlalchemy import func
+from sqlalchemy.orm import validates
from src.database import db
from src.utils import md_to_html
@@ -158,6 +159,15 @@ class Recording(db.Model):
return visible_tags
+ @validates('title')
+ def _clip_title(self, key, value):
+ # The column holds 200 characters; PostgreSQL refuses a longer value,
+ # so a long title from the API, a naming template or the AI title
+ # step is shortened here, whatever path set it
+ if isinstance(value, str) and len(value) > 200:
+ return value[:200]
+ return value
+
def get_user_notes(self, user):
"""
Get notes from user's perspective (owner or shared recipient).
diff --git a/tests/test_long_filenames.py b/tests/test_long_filenames.py
index 14d86c12..16baff63 100644
--- a/tests/test_long_filenames.py
+++ b/tests/test_long_filenames.py
@@ -39,3 +39,11 @@ def test_titles_fit_the_title_column():
assert all(len(t) == 200 for t in placeholder_titles(long_name))
assert placeholder_title(long_name) in placeholder_titles(long_name)
assert len(resolve_upload_title("y" * 300, long_name)) == 200
+
+
+def test_any_title_is_cut_to_the_column_length():
+ from src.models import Recording
+ assert len(Recording(title="t" * 400).title) == 200
+ rec = Recording(title="short")
+ rec.title = "u" * 250
+ assert len(rec.title) == 200