`@task.pyspark` does not template `config_kwargs` and `conn_id`
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 79/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- backend, data-engineering
Research direction
Start with _PySparkDecoratedOperator and its template_fields, then compare them with PySparkOperator.template_fields and the Kubernetes decorated operator pattern mentioned in the issue. Reproduce the example with render_template_fields and confirm that conn_id and config_kwargs render for the decorated operator as they do for the classic operator.
Written by the indexing model from the issue text.
Description
Under which category would you file this issue?
Providers
Apache Airflow version
3.3.2
What happened and how to reproduce it?
@task.pyspark does not render Jinja in config_kwargs (or conn_id). The same arguments passed to PySparkOperator are rendered.
PySparkOperator declares both as template fields:
PySparkOperator.template_fields == ("conn_id", "config_kwargs", "templates_dict", "op_args", "op_kwargs")
_PySparkDecoratedOperator does not define template_fields. DecoratedOperator comes before PySparkOperator in its MRO, so it inherits DecoratedOperator's fields and drops the two Spark-specific ones:
_PySparkDecoratedOperator.template_fields == ("op_args", "op_kwargs")
Templated values in config_kwargs therefore reach Spark as literal text when the decorator is used.
Reproduction:
from airflow.providers.apache.spark.operators.spark_pyspark import PySparkOperator
from airflow.sdk import DAG, task
conf = {"spark.app.name": "app-{{ run_id }}"}
with DAG("repro", schedule=None):
@task.pyspark(config_kwargs=conf)
def decorated(spark=None):
pass
decorated_op = decorated().operator
classic_op = PySparkOperator(task_id="classic", python_callable=lambda spark=None: None, config_kwargs=conf)
context = {"run_id": "manual__1"}
for op in (decorated_op, classic_op):
op.render_template_fields(context)
print(type(op).__name__, op.config_kwargs["spark.app.name"])
Output:
_PySparkDecoratedOperator app-{{ run_id }}
PySparkOperator app-manual__1
What you think should happen instead?
@task.pyspark should template conn_id and config_kwargs exactly like PySparkOperator. The decorated operator can declare the union of both sets of fields, the way _KubernetesDecoratedOperator keeps the fields of KubernetesPodOperator:
template_fields: Sequence[str] = (*DecoratedOperator.template_fields, "conn_id", "config_kwargs")
Operating System
Linux
Deployment
Virtualenv installation
Apache Airflow Provider(s)
apache-spark
Versions of Apache Airflow Providers
apache-airflow-providers-apache-spark==6.3.4
apache-airflow-providers-common-compat==1.23.0
Official Helm Chart version
Not Applicable
Kubernetes Version
No response
Helm Chart configuration
No response
Docker Image customizations
No response
Anything else?
The decorator never templated these fields: before PySparkOperator was introduced it declared template_fields = ("op_args", "op_kwargs") explicitly. The operator refactor made the inconsistency visible, since the same arguments now behave differently on the two entry points.
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
- Dominant language
- Python
- Stars
- 47.3k
- Forks
- 18.1k
- Avg merge
- 18h 16m
- Merged PRs (30d)
- 647
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/airflow
-
update virtualenv to 21.14.12 or later to resolve emSign security issuePossibly taken @arifrhm claimed this 1 day ago. Openkind:bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
apache/airflow#75858 · 2 comments ·
Maintainers usually reply within 1 day
-
Trigger UI clamps Param min/max instead of rejecting out-of-range valuesPossibly taken @muditagrawal2007 claimed this 2 days ago. Openkind:bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
apache/airflow#75747 · 1 comment ·
Maintainers usually reply within 1 day
-
Deadline Alert: No support for SmtpNotifierPossibly taken @LiaoAB claimed this 5 days ago. Openkind:bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/airflow#75452 · 1 comment ·
Maintainers usually reply within 1 day
-
RedactedIO leaks secret bytes to stdoutPossibly taken @ShivanshhhG claimed this 11 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
apache/airflow#75069 · 1 comment ·
Maintainers usually reply within 1 day
-
Task supervisor raises TypeError when a task log event has a key named target or msg, orphaning the task process and recording a successful task as failedPossibly taken @liwenjie200543 claimed this 11 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/airflow#75017 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
aws-samples/sample-per-model-bedrock#639 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 86/100
awslabs/visual-asset-management-system#937 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
project-codeflare/codeflare-sdk#1195 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
pandas-dev/pandas-stubs#2051 ·
Maintainers usually reply within 1 day