How to raise validation exception for DurationField to GUI

72 views
Skip to first unread message

Looping Ydobon

unread,
Aug 12, 2022, 10:49:54 AM8/12/22
to Django REST framework
Hello,

DurationField does not cover cases when input value cannot be converted to timestamp :

timedelta(1000000000) # OverflowError: days=1000000000; must have magnitude <= 999999999
timedelta(100000000000) # OverflowError: Python int too large to convert to C int

Therefore I made a custom/inherited DuurationField class to cover those cases and tried to raise a ValidationError inside to_internal_value().
However, only err 500 is visible on GUI side :(

Can someone give a hint on where this error is to be handled?
Enon

Linh Hoàng Ngọc

unread,
Aug 15, 2022, 1:53:44 AM8/15/22
to Django REST framework
You don't raise exceptions at serializer.

serializer.is_valid(raise_exception=Flase)



Vào lúc 21:49:54 UTC+7 ngày Thứ Sáu, 12 tháng 8, 2022, Looping Ydobon đã viết:

Looping Ydobon

unread,
Aug 16, 2022, 3:42:42 AM8/16/22
to Django REST framework
but how to handle the issue then, how can correctly I validate timedelta  data for DurationField?

Looping Ydobon

unread,
Aug 16, 2022, 7:53:11 AM8/16/22
to Django REST framework
now everything works fine - turned the Validation error raise to self.fail() call
Reply all
Reply to author
Forward
0 new messages