From 66378766aaa1454d1c820307fac2fa82b9ff1b0d Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sun, 11 Jun 2023 21:48:01 +1000 Subject: [PATCH] fix BUG-25 by using ORM not db calls direct, could not see why they worked in DEV but not PROD with NO logs - only assume sqlachemy2 doesnt like the engine execute code I used instead --- BUGs | 2 +- main.py | 22 +++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/BUGs b/BUGs index f14aec5..0014d1f 100644 --- a/BUGs +++ b/BUGs @@ -1,6 +1,6 @@ ### fix to get this working with bs 5... -#### BUGS (next-25) +#### BUGS (next-26) BUG-21: parent series now showing all books (thomas covenant series) ### DB/back-end diff --git a/main.py b/main.py index d3314fb..0697f6d 100644 --- a/main.py +++ b/main.py @@ -774,27 +774,19 @@ def stats(): def rem_books_from_loan(id): for field in request.form: rem_id=int(re.findall( '\d+', field )[0]) - try: - with db.engine.connect() as conn: - conn.exec_driver_sql( "delete from book_loan_link where book_id = {} and loan_id = {}".format( rem_id, id )) - db.session.commit() - except SQLAlchemyError as e: - st.SetAlert("danger") - st.SetMessage("Failed to remove books from loan! -- {}".format( e.orig )) - return jsonify(success=True) + bll = Book_Loan_Link.query.filter(Book_Loan_Link.loan_id==id, Book_Loan_Link.book_id == rem_id ).one() + db.session.delete(bll) + db.session.commit() + return jsonify(success=True) @app.route("/add_books_to_loan/", methods=["POST"]) @login_required def add_books_to_loan(id): for field in request.form: add_id=int(re.findall( '\d+', field )[0]) - try: - with db.engine.connect() as conn: - conn.exec_driver_sql( "insert into book_loan_link (book_id, loan_id) values ( {}, {} )".format( add_id, id )) - db.session.commit() - except SQLAlchemyError as e: - st.SetAlert("danger") - st.SetMessage("Failed to add books to loan! -- {}".format( e.orig )) + bll = Book_Loan_Link( loan_id=id, book_id=add_id ) + db.session.add(bll) + db.session.commit() return jsonify(success=True) @app.route("/rem_parent_books_from_series/", methods=["POST"])