# HG changeset patch # User Marcin Kuzminski # Date 2018-07-16 17:07:27 # Node ID 1a98e88c491916dcecae8d86134549f866d3b20c # Parent 5e0355009fbba61eefe85531b929eefc1069a930 notifications: use an explicit FK mark when creating notifications, previous way was prone to cache problems. diff --git a/rhodecode/apps/my_account/tests/test_my_account_notifications.py b/rhodecode/apps/my_account/tests/test_my_account_notifications.py --- 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(TestCo 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 --- 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 - - u.notifications.append(assoc) + Session().add(assoc) + Session().add(notification) return notification