From 1274dd589ac397f302a99955613da0e17058a734 Mon Sep 17 00:00:00 2001 From: Son NK Date: Sat, 6 Jul 2019 16:38:36 +0200 Subject: [PATCH] add delete() to ModelMixin: do NOT use the session.delete(), somehow it does a "SET" before "DELETE" --- app/auth/views/activate.py | 2 +- app/auth/views/reset_password.py | 2 +- app/developer/views/client_detail.py | 2 +- app/developer/views/index.py | 2 +- app/models.py | 5 +++-- app/oauth/views/token.py | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/auth/views/activate.py b/app/auth/views/activate.py index 08d9f5dd..520903f2 100644 --- a/app/auth/views/activate.py +++ b/app/auth/views/activate.py @@ -41,7 +41,7 @@ def activate(): login_user(user) # activation code is to be used only once - activation_code.delete() + ActivationCode.delete(activation_code.id) db.session.commit() flash("Your account has been activated", "success") diff --git a/app/auth/views/reset_password.py b/app/auth/views/reset_password.py index 0c66da00..261f20a4 100644 --- a/app/auth/views/reset_password.py +++ b/app/auth/views/reset_password.py @@ -49,7 +49,7 @@ def reset_password(): user.activated = True # remove the reset password code - reset_password_code.delete() + ResetPasswordCode.delete(reset_password_code.id) db.session.commit() login_user(user) diff --git a/app/developer/views/client_detail.py b/app/developer/views/client_detail.py index 1c9e4b05..7e0c201d 100644 --- a/app/developer/views/client_detail.py +++ b/app/developer/views/client_detail.py @@ -57,7 +57,7 @@ def client_detail(client_id): # replace all uris. TODO: optimize this? for redirect_uri in client.redirect_uris: - redirect_uri.delete() + RedirectUri.delete(redirect_uri.id) for uri in uris: RedirectUri.create(client_id=client_id, uri=uri) diff --git a/app/developer/views/index.py b/app/developer/views/index.py index 4e398341..716ccf9e 100644 --- a/app/developer/views/index.py +++ b/app/developer/views/index.py @@ -21,7 +21,7 @@ def index(): flash("You cannot remove this client", "warning") else: client_name = client.name - client.delete() + Client.delete(client.id) db.session.commit() LOG.d("Remove client %s", client) flash(f"Client {client_name} has been deleted successfully", "success") diff --git a/app/models.py b/app/models.py index bfce2305..6365ec90 100644 --- a/app/models.py +++ b/app/models.py @@ -57,8 +57,9 @@ class ModelMixin(object): def save(self): db.session.add(self) - def delete(self): - db.session.delete(self) + @classmethod + def delete(cls, obj_id): + cls.query.filter(cls.id == obj_id).delete() def __repr__(self): values = ", ".join( diff --git a/app/oauth/views/token.py b/app/oauth/views/token.py index eab47ef2..90368982 100644 --- a/app/oauth/views/token.py +++ b/app/oauth/views/token.py @@ -64,7 +64,7 @@ def get_access_token(): db.session.add(oauth_token) # Auth code can be used only once - db.session.delete(auth_code) + AuthorizationCode.delete(auth_code.id) db.session.commit()