Skip to content

Commit 06fb0d1

Browse files
committed
Fix UnboundLocalError in push() and clonedb() when no remote auth configured
`headers` was only initialized inside the `if self._remote_auth_dict or remote_auth:` block, but `headers.update(self._default_headers)` ran unconditionally. When neither remote_auth parameter nor client-level remote auth is set (the common case for local/unauthenticated connections), this raises `UnboundLocalError: cannot access local variable 'headers'`. Fix: initialize `headers = {}` before the conditional block so the subsequent `.update()` always has a valid dict to work with. Affected methods: - `Client.push()` - `Client.clonedb()` Note: `Client.pull()` is not affected — it passes `self._default_headers` directly without the conditional pattern.
1 parent 82f0319 commit 06fb0d1

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

terminusdb_client/client/Client.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,14 +2083,13 @@ def push(
20832083
"author": author,
20842084
"message": message,
20852085
}
2086+
headers = {}
20862087
if self._remote_auth_dict or remote_auth:
2087-
headers = {
2088-
"Authorization-Remote": (
2089-
self._generate_remote_header(remote_auth)
2090-
if remote_auth
2091-
else self._remote_auth()
2092-
)
2093-
}
2088+
headers["Authorization-Remote"] = (
2089+
self._generate_remote_header(remote_auth)
2090+
if remote_auth
2091+
else self._remote_auth()
2092+
)
20942093
headers.update(self._default_headers)
20952094

20962095
result = self._session.post(
@@ -2619,14 +2618,13 @@ def clonedb(
26192618
if description is None:
26202619
description = f"New database {newid}"
26212620

2621+
headers = {}
26222622
if self._remote_auth_dict or remote_auth:
2623-
headers = {
2624-
"Authorization-Remote": (
2625-
self._generate_remote_header(remote_auth)
2626-
if remote_auth
2627-
else self._remote_auth()
2628-
)
2629-
}
2623+
headers["Authorization-Remote"] = (
2624+
self._generate_remote_header(remote_auth)
2625+
if remote_auth
2626+
else self._remote_auth()
2627+
)
26302628
headers.update(self._default_headers)
26312629
rc_args = {"remote_url": clone_source, "label": newid, "comment": description}
26322630

0 commit comments

Comments
 (0)