Does anyone know how to use python assertion state...
# ask-community
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
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
cc @owen do we have any special features around asserts? I think you could just assert before returning, or have a separate assert op
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
def check_sql_query():
    assert ... # your query checking code

def my_job():
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
Although a good idea. It seems dbt model is running even though the inside function fails
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?
I have my code in a try-excpet block and i dont see any exception
hi @Francis Addae would you mind sharing the code in the check_sql_query() op?