Skip to content

Commit 92af32e

Browse files
author
James William Pye
committed
Fix tracer.
Got lost during the delegation of the protcol client.
1 parent b36b1db commit 92af32e

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

postgresql/bin/pg_python.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def command(argv = sys.argv):
5050
else:
5151
cat = None
5252

53+
trace_file = None
54+
if co.pq_trace is not None:
55+
trace_file = open(co.pq_trace, 'a')
56+
5357
try:
5458
need_prompt = False
5559
cond = None
@@ -67,6 +71,8 @@ def command(argv = sys.argv):
6771
raise SystemExit(1)
6872
connector = pg_driver.fit(category = cat, **cond)
6973
connection = connector()
74+
if trace_file is not None:
75+
connection.tracer = trace_file.write
7076
connection.connect()
7177
except pg_exc.ClientCannotConnectError as err:
7278
for att in connection.failures:
@@ -104,13 +110,8 @@ def command(argv = sys.argv):
104110
builtins_d = __builtins__
105111
restore = {k : builtins_d.get(k) for k in builtin_overload}
106112

107-
trace_file = None
108-
if co.pq_trace is not None:
109-
trace_file = open(co.pq_trace, 'a')
110113
builtins_d.update(builtin_overload)
111114
try:
112-
if trace_file is not None:
113-
connection.tracer = trace_file.write
114115
with connection:
115116
rv = pythonexec(
116117
context = pycmd.postmortem(os.environ.get('PYTHON_POSTMORTEM'))

postgresql/driver/pq3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,8 @@ def connect(self):
19641964
sf, self.connector._startup_parameters,
19651965
password = self.connector._password,
19661966
)
1967+
if hasattr(self, 'tracer'):
1968+
pq.tracer = self.tracer
19671969
# Grab the negotiation transaction before
19681970
# connecting as it will be needed later if successful.
19691971
neg = pq.xact

0 commit comments

Comments
 (0)