Skip to content

Commit 4bf9ec5

Browse files
committed
add pydantic validators
1 parent e17cfb0 commit 4bf9ec5

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

jupyter_scheduler/models.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,29 @@ class NotificationsConfig(BaseModel):
4242

4343
@validator("send_to")
4444
def validate_send_to(cls, send_to):
45-
if len(send_to) > 1000:
46-
raise ValueError("Too many email addresses. Maximum allowed is 1000.")
45+
if len(send_to) > 100:
46+
raise ValueError("Too many 'Send to' addressee identifiers. Maximum allowed is 100.")
4747
return send_to
4848

49+
@validator("send_to", each_item=True)
50+
def validate_send_to_items(cls, send_to_item):
51+
if len(send_to_item) > 100:
52+
raise ValueError(
53+
"Each 'Send to' addressee identifier should be at most 100 characters long."
54+
)
55+
return send_to_item
56+
4957
@validator("events")
50-
def validate_events(cls, events):
51-
if len(events) > 1000:
52-
raise ValueError("Too many events. Maximum allowed is 1000.")
53-
return events
58+
def validate_send_to(cls, send_to):
59+
if len(send_to) > 100:
60+
raise ValueError("Too many notification events. Maximum allowed is 100.")
61+
return send_to
62+
63+
@validator("events", each_item=True)
64+
def validate_events_items(cls, events_item):
65+
if len(events_item.value) > 100:
66+
raise ValueError("Each notification event should be at most 100 characters long.")
67+
return events_item
5468

5569

5670
class RuntimeEnvironment(BaseModel):

0 commit comments

Comments
 (0)