-2

I am writing some Airflow DAG code in Python 3.8, but there is an indentation error which I am unable to figure out. I use VScode as the IDE

Here is the code:

from airflow_env import DAG
from datetime import datetime

with DAG(
  dag_id='user-processing',
  schedule_interval='@daily',
  start_date=datetime(2022, 1, 1)) as dag:

on the terminal, the error says following: unexpected EOF while parsing but on the IDE I see expected indented block pylance python

shicha
  • 7
  • 2
  • 3
    you need to add something to the with block. even if you just add a `pass`. Python is expecting to see content there – joshmeranda Mar 23 '22 at 19:13
  • 1
    Those two errors point to the same problem, they're just expressing it in different ways. BTW, welcome to Stack Overflow! Check out the [tour], and [ask] if you want tips. – wjandrea Mar 23 '22 at 19:15
  • Have you uploaded complete code? Because i think there should be a body of `with` statement. You have instantiated a `DAG` object but you aren't using it. – Talha Asghar Mar 23 '22 at 19:19
  • thank you, it required a `task` statement to be added as part of `with/as` block. the error is gone now. I was following a tutorial for DAG where they did not talk about the task statement until few pages later. thank you all for the prompt help – shicha Mar 23 '22 at 19:27
  • Duplicate: [I'm getting an IndentationError. How do I fix it?](/q/45621722/4518341) There's a section that covers `IndentationError: expected an indented block`. (Sorry, I voted to close as typo before realizing there might be more to the misunderstanding.) – wjandrea Mar 23 '22 at 19:28

2 Answers2

2
with DAG(
  dag_id='user-processing',
  schedule_interval='@daily',
  start_date=datetime(2022, 1, 1)) as dag:

This is the beginning of a with/as block, you can't leave it empty, at least you have to specify a pass:

with DAG(...) as dag:
    pass
wjandrea
  • 28,235
  • 9
  • 60
  • 81
FLAK-ZOSO
  • 3,873
  • 4
  • 8
  • 28
1

thank you, it required a task statement to be added as part of with/as block. the error is gone now. I was following a tutorial for DAG where they did not talk about the task statement until few pages later. thank you all for the prompt help

here is the rest of the code:

from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime

def helloworld():
  print("hello world")

with DAG(
  dag_id='user-processing',
  schedule_interval='@daily',
  start_date=datetime(2022, 1, 1)) as dag:

  task1 = PythonOperator(
    task_id="hello_world",
    python_callable=helloworld
  )


task1

shicha
  • 7
  • 2