Skip to content

Commit c5e4c85

Browse files
committed
Handle empty user and participant names
Set default name for participants with no name in migration
1 parent a3e4adf commit c5e4c85

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

newdle/migrations/alembic.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[alembic]
22
file_template = %%(year)d%%(month).2d%%(day).2d_%%(hour).2d%%(minute).2d_%%(rev)s_%%(slug)s
3-
3+
script_location = newdle/migrations
44
# Logging configuration
55
[loggers]
66
keys = root,sqlalchemy,alembic
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Ensure participant names
2+
3+
Revision ID: cab5d47c1152
4+
Revises: 30b5fe7b5949
5+
Create Date: 2025-07-04 11:27:08.792500
6+
"""
7+
8+
from alembic import op
9+
10+
# revision identifiers, used by Alembic.
11+
revision = 'cab5d47c1152'
12+
down_revision = '30b5fe7b5949'
13+
branch_labels = None
14+
depends_on = None
15+
16+
17+
def upgrade():
18+
op.execute(
19+
"""
20+
UPDATE participants
21+
SET name = '?'
22+
WHERE name IS NULL OR name = '';
23+
"""
24+
)
25+
26+
27+
def downgrade():
28+
op.execute(
29+
"""
30+
UPDATE participants
31+
SET name = NULL
32+
WHERE name = '?';
33+
"""
34+
)

newdle/schemas.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ class ParticipantSchema(mm.Schema):
131131
)
132132
)
133133

134+
@validates('name')
135+
def name_not_empty(self, value):
136+
if not value or not value.strip():
137+
raise ValidationError('This field cannot be empty.')
138+
134139

135140
class RestrictedParticipantSchema(ParticipantSchema):
136141
class Meta:

0 commit comments

Comments
 (0)