Translation Execution
This page describes what happens when you call Translator.translate(...) or
Translator.translate_text(...), what gets written, what comes back on success,
and how to handle failures in Airflow code.
Two entry points
Use translate_text(...) when your input is already in memory:
result = translator.translate_text(
input_text,
filename="input.edi",
output_filename="output.csv",
context=context,
)
Use translate(...) when you want bots_airflow to read an input file and write
the final output file for you:
result = translator.translate(
"input.edi",
"output.csv",
context=context,
)
Both methods return a TranslationResult on success.
What the runtime does
For each translation call, bots_airflow currently performs these steps:
- Initialize the extracted runtime.
- Create a temporary task directory under the runtime root.
- Write the input text to a temporary input file inside that task directory.
- Parse the input using
from_editypeandfrom_messagetype. - Split the parsed interchange into messages and require exactly one message.
- Create the outbound message using
to_editypeandto_messagetype. - Call your mapping with
inn,out, and the injectedcontext. - If the mapping marks the outbound message as
DONE, stop without writing output. - Otherwise serialize the outbound message and return the result.
This package is direct parse/map/write execution. It does not use Bots routes, channels, or the translate table.
What gets written
Every translation currently writes temporary runtime files, even when you use
translate_text(...).
On every call:
- the input text is written to
TranslationResult.input_path - a temporary task directory is created at
TranslationResult.task_dir - serialized output is written to a temporary output file unless the mapping marks
the run as
DONE
When you call translate(...):
bots_airflowalso writes the final output text to theoutput_pathargument you passed in
One important detail: TranslationResult.output_path points to the temporary
runtime output file, not the final path you passed to translate(...).
Success result fields
On success, the return object includes:
runtime: runtime path information returned by the bootstrap layertask_dir: the temporary working directory for this translationinput_path: the temporary input file pathoutput_path: the temporary serialized output path, orNoneoutput_text: the serialized output text, orNonemapping_result: whatever your mapping returnedta_info: the final outboundta_infodictionary
Typical things callers read from the result are:
result.output_textfor the serialized payloadresult.mapping_resultfor map-specific counters or metadataresult.ta_info["reference"]orresult.ta_info["botskey"]for logging
Output behavior
The output behavior depends on what your mapping does.
Normal case:
- your mapping populates
out bots_airflowserializes the outbound messageresult.output_textcontains the payloadresult.output_pathpoints to the temporary runtime filetranslate(...)also writes the payload to the caller's requested output path
No-output case:
- your mapping sets
out.ta_info["statust"] = DONE result.output_pathisNoneresult.output_textisNonetranslate(...)does not create the caller's output file
Example no-output map pattern:
from botscore.constants import DONE
def main(inn, out, **kwargs):
if should_skip(inn):
out.ta_info["statust"] = DONE
return {"skipped": True}
Failure model
bots_airflow does not currently convert failures into a structured error result.
If parsing, mapping resolution, mapping execution, or file writing fails, the
exception is raised to the caller.
Common failure points include:
- invalid or missing grammar references
- mapping import errors
- parser validation errors from the inbound message
- multiple split messages in one call
- exceptions raised by your mapping
- file read or write errors in
translate(...)
If a failure occurs, you do not get a TranslationResult.
Error capture in Airflow code
If you want structured error reporting, wrap the translation call yourself:
import traceback
def run_translation(translator, input_path, output_path, context):
try:
result = translator.translate(
input_path,
output_path,
context=context,
)
return {
"ok": True,
"reference": result.ta_info.get("reference", ""),
"output_text": result.output_text,
"mapping_result": result.mapping_result,
}
except Exception as exc:
error_payload = {
"ok": False,
"reference": context.reference,
"frompartner": context.frompartner,
"topartner": context.topartner,
"error_type": type(exc).__name__,
"error": str(exc),
"traceback": traceback.format_exc(),
}
# log, persist, or push this to XCom here
raise
That is the current place to do:
- user-facing error messages
- structured logging
- retry decisions
- dead-letter storage
- alert payload generation
Recommended caller pattern
For most DAGs, treat bots_airflow as a translation primitive:
- pass explicit grammars, mapping, and context in
- read
output_text,mapping_result, andta_infoon success - catch exceptions outside the translator
- handle cleanup, retries, and reporting in Airflow or your application code
If you need retention rules for temporary task directories, implement that outside
the translation call as well. The current runtime creates temp working files but
does not expose a cleanup API on TranslationResult.