From 35d802ef68dbc853faaf0624b24117dd89a6afdc Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Thu, 7 Jan 2021 12:02:07 +0100 Subject: [PATCH 1/2] test: ensure rollback works with User entity --- frappe/core/doctype/user/test_user.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/frappe/core/doctype/user/test_user.py b/frappe/core/doctype/user/test_user.py index fb1fa4aff9..7a1ec56b8b 100644 --- a/frappe/core/doctype/user/test_user.py +++ b/frappe/core/doctype/user/test_user.py @@ -2,7 +2,7 @@ # MIT License. See license.txt from __future__ import unicode_literals -import frappe, unittest +import frappe, unittest, uuid from frappe.model.delete_doc import delete_doc from frappe.utils.data import today, add_to_date @@ -235,6 +235,29 @@ class TestUser(unittest.TestCase): self.assertRaises(frappe.ValidationError, user.reset_password, False) + def test_user_rollback(self): + """ """ + frappe.db.commit() + frappe.db.begin() + user_id = str(uuid.uuid4()) + email = f'{user_id}@example.com' + try: + frappe.flags.in_import = True # disable throttling + frappe.get_doc(dict( + doctype='User', + email=email, + first_name=user_id, + )).insert() + finally: + frappe.flags.in_import = False + + # Check user has been added + self.assertIsNotNone(frappe.db.get("User", {"email": email})) + + # Check that rollback works + frappe.db.rollback() + self.assertIsNone(frappe.db.get("User", {"email": email})) + def delete_contact(user): frappe.db.sql("DELETE FROM `tabContact` WHERE `email_id`= %s", user) From 0991911a460d2ec76bad376f59c29db272e2267f Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Thu, 7 Jan 2021 14:15:15 +0100 Subject: [PATCH 2/2] fix: remove frappe.db.commit Call to frappe.db.commit has been added here 8ba51549d3697ea415ce5a7f722b927e75f22054, at this time the User entity wasn't using create_notification_settings. The User entity uses create_notification_settings since 338bbd4a84c6e951ca3a247701c10c82e3949aa5. --- .../desk/doctype/notification_settings/notification_settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/frappe/desk/doctype/notification_settings/notification_settings.py b/frappe/desk/doctype/notification_settings/notification_settings.py index 9b124cd6f4..34726bdf8a 100644 --- a/frappe/desk/doctype/notification_settings/notification_settings.py +++ b/frappe/desk/doctype/notification_settings/notification_settings.py @@ -42,7 +42,6 @@ def create_notification_settings(user): _doc = frappe.new_doc('Notification Settings') _doc.name = user _doc.insert(ignore_permissions=True) - frappe.db.commit() @frappe.whitelist()