I am having difficulty in achieving a delete scenario. I am trying to read a set of data using joins from 2 different source tables (using Sqlalchemy models) and passing the result to a delete function. Sqlalchemy throws the error,
Can't call Query.update() or Query.delete() when join(), outerjoin(), select_from(), or from_self() has been called.
Not sure what am missing here, any help is greatly appreciated! Here's a snippet of my code,
result_set = self.session.query(Table1). \
join(Table2,
and_(Table2.col1 == Table1.col1,
Table2.col2 == func.ifnull(Table1.col2, '0'))).\
filter(Table1.col1 == '004d5b46-54aa-4da6-a182-6069f4895e7f')
result_set.delete(synchronize_session=False)
Here's the actual Sql statement of the above,
select * from table1 t1
join table2 t2 on
t2.col1 = t1.col1 and
t2.col2 = ifnull(t1.col2,'0')