Repository navigation
Description
Reproduced on 0ba094c.
Observed behavior
TranscriptionConfig(custom_spelling={}).custom_spelling raises UnboundLocalError. The constructor/setter accepts the empty mapping and stores an empty raw list, but the getter later tests its unassigned loop variable.
This also happens after clearing nonempty settings with {}, or merging {} into an unset configuration. Expected: an accepted empty setting can be read without an exception. Returning None for the empty result is consistent with the getter's existing fallback, while nonempty mappings should be unchanged.
Source: assemblyai/types.py.
Reproduction evidence
Python 3.12; install the SDK's dependencies, save the script below in the repository root, then run python reproduce.py. It was run under Pydantic 1.10.26 and 2.12.5, with websockets 15.0.1 and httpx 0.28.1.
No credentials, real service connections, or billable API calls are used. These scripts assert baseline observations and controls, not fixed behavior.
Offline reproduction script
"""Public config constructor/setter/getter only; no network."""
import json
import sys
import os
sys.dont_write_bytecode = True
sys.path.insert(0, os.environ.get("AAI_SDK_ROOT", os.getcwd()))
import assemblyai as aai
import pydantic
def check(name, config, raises=False, expected=None):
try:
value = config.custom_spelling
except UnboundLocalError as exc:
assert raises
print(json.dumps({"case": name, "exception": repr(exc),
"raw": config._raw_transcription_config.custom_spelling}))
else:
assert not raises and value == expected
print(json.dumps({"case": name, "value": value,
"raw": config._raw_transcription_config.custom_spelling}))
print(f"Python {sys.version.split()[0]}, pydantic {pydantic.__version__}")
check("default_none", aai.TranscriptionConfig())
check("explicit_none", aai.TranscriptionConfig(custom_spelling=None))
check("constructor_empty", aai.TranscriptionConfig(custom_spelling={}), raises=True)
config = aai.TranscriptionConfig(custom_spelling={"AssemblyAI": "assembly AI"})
check("nonempty_string_normalized", config, expected={"AssemblyAI": ["assembly AI"]})
config.set_custom_spelling({}, override=False)
check("empty_merge_preserves", config, expected={"AssemblyAI": ["assembly AI"]})
config.set_custom_spelling({"Kubernetes": ["k8s", "kubernetes"]}, override=False)
check("nonempty_merge", config, expected={"AssemblyAI": ["assembly AI"], "Kubernetes": ["k8s", "kubernetes"]})
config.set_custom_spelling({})
check("clear_with_empty_override", config, raises=True)
config.set_custom_spelling(None)
check("clear_with_none", config)
config.set_custom_spelling({}, override=False)
check("empty_merge_into_none", config, raises=True)
config.set_custom_spelling({"Kubernetes": ["k8s", "kubernetes"]})
check("nonempty_override_recovers", config, expected={"Kubernetes": ["k8s", "kubernetes"]})
check("fresh_setter_empty", aai.TranscriptionConfig().set_custom_spelling({}), raises=True)Observed output
Python 3.12.13, pydantic 2.12.5
{"case": "default_none", "value": null, "raw": null}
{"case": "explicit_none", "value": null, "raw": null}
{"case": "constructor_empty", "exception": "UnboundLocalError(\"cannot access local variable 'custom_spelling' where it is not associated with a value\")", "raw": []}
{"case": "nonempty_string_normalized", "value": {"AssemblyAI": ["assembly AI"]}, "raw": [{"from": ["assembly AI"], "to": "AssemblyAI"}]}
{"case": "empty_merge_preserves", "value": {"AssemblyAI": ["assembly AI"]}, "raw": [{"from": ["assembly AI"], "to": "AssemblyAI"}]}
{"case": "nonempty_merge", "value": {"AssemblyAI": ["assembly AI"], "Kubernetes": ["k8s", "kubernetes"]}, "raw": [{"from": ["assembly AI"], "to": "AssemblyAI"}, {"from": ["k8s", "kubernetes"], "to": "Kubernetes"}]}
{"case": "clear_with_empty_override", "exception": "UnboundLocalError(\"cannot access local variable 'custom_spelling' where it is not associated with a value\")", "raw": []}
{"case": "clear_with_none", "value": null, "raw": null}
{"case": "empty_merge_into_none", "exception": "UnboundLocalError(\"cannot access local variable 'custom_spelling' where it is not associated with a value\")", "raw": []}
{"case": "nonempty_override_recovers", "value": {"Kubernetes": ["k8s", "kubernetes"]}, "raw": [{"from": ["k8s", "kubernetes"], "to": "Kubernetes"}]}
{"case": "fresh_setter_empty", "exception": "UnboundLocalError(\"cannot access local variable 'custom_spelling' where it is not associated with a value\")", "raw": []}
Controls and scope
Default/explicit None, nonempty string and list replacements, nonempty merges, empty merges into existing settings, clearing with None, and recovery through nonempty override all passed. Distinct from #92's nonempty list-valued spelling problem.
All six Python executions (three reproductions under both Pydantic versions) exited 0.
Activity