Merge remote-tracking branch 'fix_lobject_mode'

This commit is contained in:
Daniele Varrazzo 2017-04-19 01:06:08 +01:00
commit bd34c86aba
2 changed files with 11 additions and 1 deletions

View File

@ -398,7 +398,7 @@ static int
lobject_init(PyObject *obj, PyObject *args, PyObject *kwds) lobject_init(PyObject *obj, PyObject *args, PyObject *kwds)
{ {
Oid oid = InvalidOid, new_oid = InvalidOid; Oid oid = InvalidOid, new_oid = InvalidOid;
const char *smode = ""; const char *smode = NULL;
const char *new_file = NULL; const char *new_file = NULL;
PyObject *conn = NULL; PyObject *conn = NULL;
@ -407,6 +407,9 @@ lobject_init(PyObject *obj, PyObject *args, PyObject *kwds)
&oid, &smode, &new_oid, &new_file)) &oid, &smode, &new_oid, &new_file))
return -1; return -1;
if (!smode)
smode = "";
return lobject_setup((lobjectObject *)obj, return lobject_setup((lobjectObject *)obj,
(connectionObject *)conn, oid, smode, new_oid, new_file); (connectionObject *)conn, oid, smode, new_oid, new_file);
} }

View File

@ -110,6 +110,13 @@ class LargeObjectTests(LargeObjectTestCase):
self.assertEqual(lo2.oid, lo.oid) self.assertEqual(lo2.oid, lo.oid)
self.assertEqual(lo2.closed, True) self.assertEqual(lo2.closed, True)
def test_mode_defaults(self):
lo = self.conn.lobject()
lo2 = self.conn.lobject(mode=None)
lo3 = self.conn.lobject(mode="")
self.assertEqual(lo.mode, lo2.mode)
self.assertEqual(lo.mode, lo3.mode)
def test_close_connection_gone(self): def test_close_connection_gone(self):
lo = self.conn.lobject() lo = self.conn.lobject()
self.conn.close() self.conn.close()