0

I am able to insert records into the database:

new_user = Users(new_register_email, new_password, verification_code)
db.session.add(new_user)
db.session.commit()

database query 1

I am able to query records inserted out of the database:

 user_to_verify = Users.query.filter_by(email=uid).first()

debug image 1

I am not able to update records:

 user_to_verify = Users.query.filter_by(email=uid).first()
 if user_to_verify:
    if user_to_verify.verification_code == returned_verification_code:
        user_to_verify.verified = True
        db.session.commit()

enter image description here

With debugging I am verifying that the code listed above is run but the verified field in the database is not updated. This is fallowing info here https://www.tutorialspoint.com/sqlalchemy/sqlalchemy_orm_updating_objects.htm

UPDATE: image of debugger at point where update should occure enter image description here

user6252584
  • 229
  • 2
  • 8

2 Answers2

0

I am not sure how valid this is but it seems to be working, Added:

db.session.merge(user_to_verify)

before commiting I found this solution here: Flask-SQLalchemy update a row's information

If this is not valid or bad practice please correct me, thank you!

user6252584
  • 229
  • 2
  • 8
0

Can you try:

user_to_verify.verified = True
db.session.add(user_to_verify)
db.session.commit()

you can also add

import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

for debugging

idoshveki
  • 133
  • 1
  • 1
  • 6