File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,16 +56,11 @@ impl<'p> Serialize for DefaultSerializer {
5656 self . ptr,
5757 std:: ptr:: null_mut( ) as * mut pyo3:: ffi:: PyObject
5858 ) ) ;
59- if default_obj. is_null ( ) {
59+ if unlikely ! ( default_obj. is_null( ) ) {
6060 err ! ( format_args!(
6161 "Type is not JSON serializable: {}" ,
6262 obj_name!( ob_type!( self . ptr) )
6363 ) )
64- } else if !ffi ! ( PyErr_Occurred ( ) ) . is_null ( ) {
65- err ! ( format_args!(
66- "Type raised exception in default function: {}" ,
67- obj_name!( ob_type!( self . ptr) )
68- ) )
6964 } else {
7065 let res = SerializePyObject :: new (
7166 default_obj,
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ impl UUID {
2727 // test_uuid_overflow
2828 pyo3:: ffi:: _PyLong_AsByteArray (
2929 py_int as * mut pyo3:: ffi:: PyLongObject ,
30- buffer. as_ptr ( ) as * const c_uchar ,
30+ buffer. as_ptr ( ) as * mut c_uchar ,
3131 16 ,
3232 1 , // little_endian
3333 0 , // is_signed
Original file line number Diff line number Diff line change 11arrow
22dataclasses ;python_version < "3.7"
33numpy ;platform_machine == "x86_64" and python_version<"3.9"
4- pendulum ;sys_platform == "linux" and python_version< "3.9" and platform_machine=="x86_64"
4+ pendulum ;sys_platform == "linux" and platform_machine=="x86_64"
55psutil
66pytest
77pytz
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ def default(obj):
2626 return obj .cur
2727
2828
29+ def default_raises (obj ):
30+ raise TypeError
31+
32+
2933class TypeTests (unittest .TestCase ):
3034 def test_default_not_callable (self ):
3135 """
@@ -95,6 +99,15 @@ def default(obj):
9599 ran = True
96100 self .assertTrue (ran )
97101
102+ def test_default_exception_type (self ):
103+ """
104+ dumps() TypeError in default() raises orjson.JSONEncodeError
105+ """
106+ ref = Custom ()
107+
108+ with self .assertRaises (orjson .JSONEncodeError ):
109+ orjson .dumps (ref , default = default_raises )
110+
98111 def test_default_func_nested_str (self ):
99112 """
100113 dumps() default function nested str
You can’t perform that action at this time.
0 commit comments