Skip to content

fix(types): keep raw_transcription_config values and rebuild transcript.config from them - #288

Open
RishavTiwari25 wants to merge 3 commits into
AssemblyAI:masterfrom
RishavTiwari25:fix/raw-transcription-config
Open

RishavTiwari25 wants to merge 3 commits into
AssemblyAI:masterfrom
RishavTiwari25:fix/raw-transcription-config

Conversation

@RishavTiwari25

Copy link
Copy Markdown

Summary

Two related bugs in TranscriptionConfig / Transcript.config.

1. TranscriptionConfig(raw_transcription_config=raw) erased almost all of raw's values.
The constructor stored raw and then ran every setter (self.language_code = language_code, self.punctuate = punctuate, ...) with the arguments' None defaults, writing straight onto raw. So

raw = aai.RawTranscriptionConfig(language_code="de", punctuate=False)
aai.TranscriptionConfig(raw_transcription_config=raw).language_code  # None

and raw itself was mutated to language_code=None, punctuate=None. The docstring says explicit arguments should take priority over the raw config, not wipe it.

2. transcript.config raised for some completed transcripts.
config_from_response passed the response's fields as TranscriptionConfig(**fields). That breaks when a field's API shape differs from the constructor argument, or the field is not an argument at all:

  • custom_spelling: the API echoes [{"from": [...], "to": "..."}], but set_custom_spelling expects a {to: from} dict -> AttributeError: 'list' object has no attribute 'items'.
  • language_detection_results: a RawTranscriptionConfig field but not a constructor argument -> TypeError: unexpected keyword argument.

Changes

  • assemblyai/types.py: the constructor applies the explicit arguments to a fresh RawTranscriptionConfig, then copies only the non-None ones onto the passed raw_transcription_config (explicit arguments still win) and keeps that object.
  • assemblyai/prerecorded/v2/_base.py: config_from_response builds a RawTranscriptionConfig from the response fields and passes it as raw_transcription_config (this relies on fix 1).
  • assemblyai/__version__.py: 1.8.2 -> 1.8.3 for the version bump check.

Tests

  • tests/unit/test_config.py: raw values are kept (incl. punctuate=False and custom_spelling); explicit arguments override raw values while the rest are kept.
  • tests/unit/test_transcript.py: transcript.config for a response with custom_spelling and one with language_detection_results.

All four fail on master and pass with the fix. pytest tests/unit: 923 passed, 1 failure that also fails on master on Windows (test_upload_request_omits_content_length_for_an_unsized_stream, unrelated). ruff check / ruff format --check clean on the changed files; mypy reports no new errors.

…pt.config from them

TranscriptionConfig(raw_transcription_config=raw) assigned every constructor argument onto raw, so their None defaults erased nearly all of raw's values.

Transcript.config passed the response's fields as constructor arguments, which raised for a transcript with custom_spelling (the API returns a list of from/to objects, the argument is a dict) or language_detection_results (not an argument at all). It now builds a RawTranscriptionConfig and passes that.
Take upstream's assemblyai/__version__.py (1.9.0); the branch's own
1.8.3 bump is superseded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant