Am trying to delete a user from my subscribers list , but the whole subscribers deleting automatically .
Here is my subscribe function:
def subscribe(self, user_id):
if not self.is_subscriber(user_id):
db.engine.execute(
subscribers.insert(),
client_id = self.id,
user_id = user_id
)
db.session.commit()
else:
return False
The unsubscribe function:
def unsubscribe(self, user_id):
if self.is_subscriber(user_id):
db.engine.execute(
subscribers.delete(),
client_id = self.id,
user_id = user_id
)
db.session.commit()
else:
return False
By that if i tried to unsubscribe it should delete that specific user , but in my situation the whole users get deleted from the table, why is that, please, anybody can help to solve the problem here ??
Edit:
If i tried to delete the client_id from the query and just to delete the user_id, i get this error:
UnmappedInstanceError: Class '__builtin__.int' is not mapped
also with db.session.delete(user_id) command !! .
Also i've created this function, which by i get also the same error:
def unsubscriber(self, user_id):
select_subscribers = subscribers.select(
db.and_(
subscribers.c.user_id == user_id,
subscribers.c.client_id == self.id
)
)
rs = db.engine.execute(select_subscribers)
return False if rs.rowcount == 0 else db.session.delete(user_id),
db.session.commit()