Skip to content

Commit ae2f60a

Browse files
author
James William Pye
committed
Fix tracer.
Got lost during the delegation of the protcol client.
1 parent 9e14ad5 commit ae2f60a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

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:
@@ -105,13 +111,8 @@ def command(argv = sys.argv):
105111
builtins_d = __builtins__
106112
restore = {k : builtins_d.get(k) for k in builtin_overload}
107113

108-
trace_file = None
109-
if co.pq_trace is not None:
110-
trace_file = open(co.pq_trace, 'a')
111114
builtins_d.update(builtin_overload)
112115
try:
113-
if trace_file is not None:
114-
connection.tracer = trace_file.write
115116
with connection:
116117
rv = pythonexec(
117118
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
@@ -1851,6 +1851,8 @@ def connect(self):
18511851
sf, self.connector._startup_parameters,
18521852
password = self.connector._password,
18531853
)
1854+
if hasattr(self, 'tracer'):
1855+
pq.tracer = self.tracer
18541856
# Grab the negotiation transaction before
18551857
# connecting as it will be needed later if successful.
18561858
neg = pq.xact

0 commit comments

Comments
 (0)