mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-23 01:16:34 +03:00
Invalidate large objects after a two-phase commit operation
This commit is contained in:
parent
935c25730a
commit
48588e5f69
|
@ -610,6 +610,8 @@ pq_tpc_command_locked(connectionObject *conn, const char *cmd, const char *tid,
|
|||
Dprintf("_pq_tpc_command: pgconn = %p, command = %s",
|
||||
conn->pgconn, cmd);
|
||||
|
||||
conn->mark += 1;
|
||||
|
||||
/* convert the xid into the postgres transaction_id and quote it. */
|
||||
if (!(etid = psycopg_escape_string((PyObject *)conn, tid, 0, NULL, NULL)))
|
||||
{ goto exit; }
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from testutils import unittest, decorate_all_tests
|
||||
from testutils import unittest, decorate_all_tests, skip_if_tpc_disabled
|
||||
|
||||
import psycopg2
|
||||
import psycopg2.extensions
|
||||
|
@ -53,7 +53,7 @@ def skip_if_green(f):
|
|||
class LargeObjectMixin(object):
|
||||
# doesn't derive from TestCase to avoid repeating tests twice.
|
||||
def setUp(self):
|
||||
self.conn = psycopg2.connect(tests.dsn)
|
||||
self.conn = self.connect()
|
||||
self.lo_oid = None
|
||||
self.tmpdir = None
|
||||
|
||||
|
@ -74,6 +74,9 @@ class LargeObjectMixin(object):
|
|||
lo.unlink()
|
||||
self.conn.close()
|
||||
|
||||
def connect(self):
|
||||
return psycopg2.connect(tests.dsn)
|
||||
|
||||
|
||||
class LargeObjectTests(LargeObjectMixin, unittest.TestCase):
|
||||
def test_create(self):
|
||||
|
@ -312,6 +315,28 @@ class LargeObjectTests(LargeObjectMixin, unittest.TestCase):
|
|||
self.assertTrue(os.path.exists(filename))
|
||||
self.assertEqual(open(filename, "rb").read(), "some data")
|
||||
|
||||
@skip_if_tpc_disabled
|
||||
def test_read_after_tpc_commit(self):
|
||||
self.conn.tpc_begin('test_lobject')
|
||||
lo = self.conn.lobject()
|
||||
self.lo_oid = lo.oid
|
||||
self.conn.tpc_commit()
|
||||
|
||||
self.assertRaises(psycopg2.ProgrammingError, lo.read, 5)
|
||||
|
||||
@skip_if_tpc_disabled
|
||||
def test_read_after_tpc_prepare(self):
|
||||
self.conn.tpc_begin('test_lobject')
|
||||
lo = self.conn.lobject()
|
||||
self.lo_oid = lo.oid
|
||||
self.conn.tpc_prepare()
|
||||
|
||||
try:
|
||||
self.assertRaises(psycopg2.ProgrammingError, lo.read, 5)
|
||||
finally:
|
||||
self.conn.tpc_commit()
|
||||
|
||||
|
||||
decorate_all_tests(LargeObjectTests, skip_if_no_lo)
|
||||
decorate_all_tests(LargeObjectTests, skip_if_green)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user