https://dagster.io/ logo
#dagster-support
Title
# dagster-support
f

Francis Addae

04/20/2022, 8:16 PM
Does anyone know how to use python assertion statements with dagster return variables? Just trying to validate a sql query before I push dbt to run it using dagster
Copy code
@job
def my_pipeline():
    e = checkETL.check_sql_query()
    #assert e == True
    #run dbt Model

if __name__ == "__main__":
    result = my_pipeline.execute_in_process()
    # assert result.output_value ==True
j

johann

04/21/2022, 3:14 PM
cc @owen do we have any special features around asserts? I think you could just assert before returning, or have a separate assert op
o

owen

04/21/2022, 4:29 PM
no special features here, johann's suggestion of putting the assert inside the check_sql_query() op is probably what you want. the code underneath the @job decorator is just for defining the structure of your job, and should not contain any actual logic. the way i'd structure this is something like
Copy code
@op
def check_sql_query():
    assert ... # your query checking code

@job
def my_job():
    dbt_run_op(start_after=check_sql_query())
this way, if the check fails, then the entire check_sql_query op will fail, meaning that its downstream op (dbt_run_op()) will not run, which I believe is the behavior you're looking for
1
f

Francis Addae

04/21/2022, 8:14 PM
Although a good idea. It seems dbt model is running even though the inside function fails
o

owen

04/21/2022, 8:43 PM
that's strange -- I'd expect the entire check_sql_query() op to fail if the assert raises an exception
just to confirm -- do you see the exception in the event logs?
f

Francis Addae

04/21/2022, 8:50 PM
Nope
I have my code in a try-excpet block and i dont see any exception
o

owen

04/21/2022, 9:39 PM
hi @Francis Addae would you mind sharing the code in the check_sql_query() op?
f

Francis Addae

04/22/2022, 12:44 AM
Sure
7 Views