mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 02:13:44 +03:00
Don't create/register a json array typecaster if no oid provided
This commit is contained in:
parent
5645e7adef
commit
a3418052e9
|
@ -202,7 +202,10 @@ def _create_json_typecasters(oid, array_oid, loads=None):
|
|||
return loads(s)
|
||||
|
||||
JSON = new_type((oid, ), 'JSON', typecast_json)
|
||||
JSONARRAY = new_array_type((array_oid, ), "JSONARRAY", JSON)
|
||||
if array_oid is not None:
|
||||
JSONARRAY = new_array_type((array_oid, ), "JSONARRAY", JSON)
|
||||
else:
|
||||
JSONARRAY = None
|
||||
|
||||
return JSON, JSONARRAY
|
||||
|
||||
|
|
|
@ -1015,6 +1015,18 @@ class JsonTestCase(unittest.TestCase):
|
|||
curs.execute("""select NULL::json[]""")
|
||||
self.assertEqual(curs.fetchone()[0], None)
|
||||
|
||||
@skip_if_no_json_module
|
||||
def test_no_array_oid(self):
|
||||
curs = self.conn.cursor()
|
||||
t1, t2 = psycopg2.extras.register_json(curs, oid=25)
|
||||
self.assertEqual(t1.values[0], 25)
|
||||
self.assertEqual(t2, None)
|
||||
|
||||
curs.execute("""select '{"a": 100.0, "b": null}'::text""")
|
||||
data = curs.fetchone()[0]
|
||||
self.assertEqual(data['a'], 100)
|
||||
self.assertEqual(data['b'], None)
|
||||
|
||||
|
||||
def test_suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
|
Loading…
Reference in New Issue
Block a user