Does anyone know how to use python assertion state...
# ask-community
f
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
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
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
Although a good idea. It seems dbt model is running even though the inside function fails
o
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
Nope
I have my code in a try-excpet block and i dont see any exception
o
hi @Francis Addae would you mind sharing the code in the check_sql_query() op?
f
Sure