diff --git a/app.py b/app.py index cd61a68..cb3ffc4 100644 --- a/app.py +++ b/app.py @@ -38,7 +38,7 @@ app.config["KI_LDAP_AUTH_PASSWORD"] = os.getenv("KI_LDAP_AUTH_PASSWORD") app.config["KI_LDAP_BASE_DN"] = os.getenv("KI_LDAP_BASE_DN") CORS(app) -db = SQLAlchemy(app) +db = SQLAlchemy(app, session_options={"future": True}) migrate = Migrate(app, db, compare_type=True) app.logger.info("Hello from KI") diff --git a/ki/actions/seed.py b/ki/actions/seed.py index eeafdb1..9edf8e9 100644 --- a/ki/actions/seed.py +++ b/ki/actions/seed.py @@ -19,7 +19,7 @@ def seed_contacttypes(): for contacttype in csv_reader: id = int(contacttype["id"]) - db_contacttype = ContactType.query.get(id) + db_contacttype = db.session.get(ContactType, id) if db_contacttype is None: db.session.add(ContactType(id=int(contacttype["id"]), name=contacttype["name"])) @@ -99,7 +99,7 @@ def seed(dev: bool): for skill in skills_csv_reader: id = int(skill["id"]) - db_skill = Skill.query.get(id) + db_skill = db.session.get(Skill, id) if db_skill is None: db.session.add(Skill(id=int(skill["id"]), name=skill["name"])) @@ -113,7 +113,7 @@ def seed(dev: bool): for iso in iso_csv_reader: id = iso["639-1"] - db_language = Language.query.get(id) + db_language = db.session.get(Language, id) if db_language is None: db.session.add(Language(id=iso["639-1"], name=iso["Sprache"])) diff --git a/ki/handlers/update_profile.py b/ki/handlers/update_profile.py index 377b4c5..2e97526 100644 --- a/ki/handlers/update_profile.py +++ b/ki/handlers/update_profile.py @@ -33,7 +33,7 @@ def update_languages(profile, languages_data): if "id" not in language_data["language"]: continue - language = Language.query.get(language_data["language"]["id"]) + language = db.session.get(Language, language_data["language"]["id"]) profile_language = ProfileLanguage.query.filter(ProfileLanguage.profile == profile, ProfileLanguage.language == language).first() @@ -110,7 +110,7 @@ def update_contacts(profile, contacts_data): if "id" in contact_data: contact_id = int(contact_data["id"]) contact_ids_to_be_deleted.remove(contact_id) - contact = Contact.query.get(contact_id) + contact = db.session.get(Contact, contact_id) else: contact = Contact(profile=profile, contacttype=contacttype) db.session.add(contact) @@ -122,7 +122,7 @@ def update_contacts(profile, contacts_data): def update_profile(user_id: int): - user = User.query.get(user_id) + user = db.session.get(User, user_id) if user is None: return make_response({}, 404) diff --git a/ki/routes.py b/ki/routes.py index 946e624..4bb73e1 100644 --- a/ki/routes.py +++ b/ki/routes.py @@ -10,7 +10,7 @@ from ki.auth import auth from ki.handlers import find_profiles as find_profiles_handler from ki.handlers import update_profile as update_profile_handler from ki.models import ContactType, Language, Skill, Token, User -from app import app +from app import app, db content_type_svg = "image/svg+xml" content_type_png = "image/png" @@ -66,7 +66,7 @@ def handle_completion_request(model, key): def handle_icon_request(model, id, path): - object = model.query.get(id) + object = db.session.get(model, id) if object is None: return make_response({}, 404)