mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-07-02 10:43:05 +03:00
Fixed json typecaster with NULL input
This commit is contained in:
parent
7386b8327c
commit
9b2ad7abb5
|
@ -197,6 +197,8 @@ def _create_json_typecasters(oid, array_oid, loads=None):
|
||||||
loads = json.loads
|
loads = json.loads
|
||||||
|
|
||||||
def typecast_json(s, cur):
|
def typecast_json(s, cur):
|
||||||
|
if s is None:
|
||||||
|
return None
|
||||||
return loads(s)
|
return loads(s)
|
||||||
|
|
||||||
JSON = new_type((oid, ), 'JSON', typecast_json)
|
JSON = new_type((oid, ), 'JSON', typecast_json)
|
||||||
|
|
|
@ -1005,6 +1005,16 @@ class JsonTestCase(unittest.TestCase):
|
||||||
self.assert_(isinstance(data[0]['a'], Decimal))
|
self.assert_(isinstance(data[0]['a'], Decimal))
|
||||||
self.assertEqual(data[0]['a'], Decimal('100.0'))
|
self.assertEqual(data[0]['a'], Decimal('100.0'))
|
||||||
|
|
||||||
|
@skip_if_no_json_module
|
||||||
|
@skip_if_no_json_type
|
||||||
|
def test_null(self):
|
||||||
|
psycopg2.extras.register_json(self.conn)
|
||||||
|
curs = self.conn.cursor()
|
||||||
|
curs.execute("""select NULL::json""")
|
||||||
|
self.assertEqual(curs.fetchone()[0], None)
|
||||||
|
curs.execute("""select NULL::json[]""")
|
||||||
|
self.assertEqual(curs.fetchone()[0], None)
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user