Alex van Winkel
Alex van Winkel

Reputation: 41

Why aren't the rows being deleted by this code ? ( Flask-SQLAlchemy )

Here is a part of my code : I am trying to delete all the rows that match the criteria instructor=chosen_student. Now I know for a fact this query is working. But the rows are just NOT removed from the table ?!?!

class Alert(db.Model):

    __tablename__ = "alerts"

    id = db.Column(db.Integer, primary_key=True)
    alert = db.Column(db.String(4096))
    CW_class = db.Column(db.String(612))
    instructor = db.Column(db.String(612))  #instructor = username !
    date = db.Column(db.String(612))
    importDate = db.Column(db.String(612))

input = request.form.get('student')
list = input.split('-')
action = list[0]
chosen_student = list[1]
delete_q = Alert.query.filter_by(instructor=chosen_student).delete()
msg = str(delete_q)
db.session.commit

When I run this code, printing delete_q will output '2', which is correct: there are 2 records that match the selection criteria(instructor=chosen_student). But when running a select query afterward, the 2 rows are NOT deleted...

Does anyone have a clue why?

Upvotes: 1

Views: 201

Answers (1)

Aliaksei Piatrouski
Aliaksei Piatrouski

Reputation: 77

db.session.commit()

(pay attention to parentheses)

You can use any linters (such as pylint or flake8) to avoid such typos in the future.

Upvotes: 2

Related Questions