Airflow运行DataFlow自执行Jar报错:NoneType不可迭代求助
That error typically means somewhere in your code (or Airflow's internal logic) is trying to iterate over a value that's None instead of an iterable object like a list or tuple. Let's break down the most likely fixes for your specific setup (Python 2.7.10, Airflow 1.9.0, Pandas 0.22.0):
1. Validate Your DataFlow Operator Configuration
The most common culprit here is missing or misconfigured parameters in your DataFlowJavaOperator task. Double-check these critical fields:
- Jar path: Ensure you're passing an absolute, valid path to your DataFlow JAR (not a relative path that might resolve to
Nonein Airflow's execution context). - Arguments parameter: Never set
arguments=None— if you don't need extra arguments, pass an empty listarguments=[]instead. Airflow's operator likely tries to iterate over this parameter to build the command line, which fails if it'sNone.
Example of a valid operator setup:
from airflow.contrib.operators.dataflow_operator import DataFlowJavaOperator from airflow.models import DAG from datetime import datetime default_args = { 'owner': 'airflow', 'start_date': datetime(2018, 3, 26), } dag = DAG('test-dag', default_args=default_args) run_dataflow_task = DataFlowJavaOperator( task_id='hello-dag', jar='/Users/henry/path/to/your/dataflow.jar', # Absolute path arguments=['--input=gs://your-bucket/input', '--output=gs://your-bucket/output'], gcp_conn_id='google_cloud_default', dag=dag )
2. Get the Full Error Traceback
Your provided traceback is truncated, which hides the exact line of code triggering the error. Capture the full stack trace by redirecting command output to a file:
airflow test test-dag hello-dag 2018-03-26 > airflow_error.log 2>&1
Open airflow_error.log and look for the line that starts with TypeError: 'NoneType' object is not iterable — the preceding lines will show exactly which function/parameter is causing the issue.
3. Check for Airflow 1.9.0 Python 2.7 Compatibility Bugs
Airflow 1.9.0 is a legacy version, and some operators have known edge cases with Python 2.7. For example:
- The
DataFlowJavaOperatorin older Airflow versions might not properly handleNonevalues for optional parameters. If you're using any optional fields (likelabelsorjob_name), ensure they're either set to valid values or omitted entirely (don't set them toNone).
4. Verify Jar and Environment Validity
- Test your DataFlow JAR outside Airflow first: Run the equivalent
java -jar /path/to/your.jarcommand manually to confirm the JAR itself works and doesn't throw unexpected errors. - Ensure the Airflow user has read access to the JAR file and any associated GCP resources (if using DataFlow on GCP).
5. Rule Out Pandas-Related Issues
While the error doesn't directly point to Pandas, if your DAG uses Pandas to generate arguments for the DataFlow task, check that any Pandas output (like a list of parameters) isn't returning None accidentally. For example, if you're reading a config file with Pandas and parsing arguments, confirm the parsed result is always an iterable.
内容的提问来源于stack exchange,提问作者Henry Chen

