From c4e1783d4ffaaab47da8375650f6604fe89e22c9 Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Mon, 16 Jul 2018 19:07:27 +0200 Subject: [PATCH] notifications: use an explicit FK mark when creating notifications, previous way was prone to cache problems. --- .../apps/my_account/tests/test_my_account_notifications.py | 1 + rhodecode/model/db.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rhodecode/apps/my_account/tests/test_my_account_notifications.py b/rhodecode/apps/my_account/tests/test_my_account_notifications.py index fdadeb95..248f7a7d 100644 --- a/rhodecode/apps/my_account/tests/test_my_account_notifications.py +++ b/rhodecode/apps/my_account/tests/test_my_account_notifications.py @@ -155,6 +155,7 @@ class TestNotificationsController(TestController): notification = NotificationModel().create( created_by=cur_user, notification_subject=subject, notification_body=notif_body, recipients=[cur_user, u1, u2]) + Session().commit() response = self.app.get( route_path('notifications_show', diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py index 9d06f822..3bec42c9 100644 --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -3909,16 +3909,18 @@ class Notification(Base, BaseModel): notification.type_ = type_ notification.created_on = datetime.datetime.now() + # For each recipient link the created notification to his account for u in recipients: assoc = UserNotification() + assoc.user_id = u.user_id assoc.notification = notification # if created_by is inside recipients mark his notification # as read if u.user_id == created_by.user_id: assoc.read = True + Session().add(assoc) - u.notifications.append(assoc) Session().add(notification) return notification