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

This commit is contained in:
2023-06-11 21:48:01 +10:00
parent 65c701c6a0
commit 66378766aa
2 changed files with 8 additions and 16 deletions

2
BUGs
View File

@@ -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

16
main.py
View File

@@ -774,13 +774,9 @@ 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 ))
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()
except SQLAlchemyError as e:
st.SetAlert("danger")
st.SetMessage("Failed to remove books from loan! -- {}".format( e.orig ))
return jsonify(success=True)
@app.route("/add_books_to_loan/<id>", methods=["POST"])
@@ -788,13 +784,9 @@ def rem_books_from_loan(id):
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 ))
bll = Book_Loan_Link( loan_id=id, book_id=add_id )
db.session.add(bll)
db.session.commit()
except SQLAlchemyError as e:
st.SetAlert("danger")
st.SetMessage("Failed to add books to loan! -- {}".format( e.orig ))
return jsonify(success=True)
@app.route("/rem_parent_books_from_series/<pid>", methods=["POST"])