We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove Share doesn't disappear 
## Description of the issue
When the read Permission of a Share is removed by de-selecting the checkbox, then the corresponding DocShare is removed in the Backend, but the checkbox is automatically re-selected in the frontend. After a refresh, the share 


## Context information (for bug reports)

**Output of `bench version`**
```
frappe 14.x.x-develop
```

## Steps to reproduce the issue

1. Open an arbitrary Document
2. Add a share with read permissions
3. Remove the read permission by clicking the checkbox

### Observed result
The checkbox is automatically re-selected

### Expected result
The share entry disappears

## Additional information



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `frappe/share.py`
Content:
```
1 # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2 # License: MIT. See LICENSE
3 
4 import frappe
5 from frappe import _
6 from frappe.desk.doctype.notification_log.notification_log import (
7 	enqueue_create_notification,
8 	get_title,
9 	get_title_html,
10 )
11 from frappe.desk.form.document_follow import follow_document
12 from frappe.utils import cint
13 
14 
15 @frappe.whitelist()
16 def add(
17 	doctype, name, user=None, read=1, write=0, submit=0, share=0, everyone=0, flags=None, notify=0
18 ):
19 	"""Share the given document with a user."""
20 	if not user:
21 		user = frappe.session.user
22 
23 	if not (flags or {}).get("ignore_share_permission"):
24 		check_share_permission(doctype, name)
25 
26 	share_name = get_share_name(doctype, name, user, everyone)
27 
28 	if share_name:
29 		doc = frappe.get_doc("DocShare", share_name)
30 	else:
31 		doc = frappe.new_doc("DocShare")
32 		doc.update(
33 			{"user": user, "share_doctype": doctype, "share_name": name, "everyone": cint(everyone)}
34 		)
35 
36 	if flags:
37 		doc.flags.update(flags)
38 
39 	doc.update(
40 		{
41 			# always add read, since you are adding!
42 			"read": 1,
43 			"write": cint(write),
44 			"submit": cint(submit),
45 			"share": cint(share),
46 		}
47 	)
48 
49 	doc.save(ignore_permissions=True)
50 	notify_assignment(user, doctype, name, everyone, notify=notify)
51 
52 	if frappe.get_cached_value("User", user, "follow_shared_documents"):
53 		follow_document(doctype, name, user)
54 
55 	return doc
56 
57 
58 def remove(doctype, name, user, flags=None):
59 	share_name = frappe.db.get_value(
60 		"DocShare", {"user": user, "share_name": name, "share_doctype": doctype}
61 	)
62 
63 	if share_name:
64 		frappe.delete_doc("DocShare", share_name, flags=flags)
65 
66 
67 @frappe.whitelist()
68 def set_permission(doctype, name, user, permission_to, value=1, everyone=0):
69 	"""Set share permission."""
70 	check_share_permission(doctype, name)
71 
72 	share_name = get_share_name(doctype, name, user, everyone)
73 	value = int(value)
74 
75 	if not share_name:
76 		if value:
77 			share = add(doctype, name, user, everyone=everyone, **{permission_to: 1})
78 		else:
79 			# no share found, nothing to remove
80 			share = {}
81 			pass
82 	else:
83 		share = frappe.get_doc("DocShare", share_name)
84 		share.flags.ignore_permissions = True
85 		share.set(permission_to, value)
86 
87 		if not value:
88 			# un-set higher-order permissions too
89 			if permission_to == "read":
90 				share.read = share.write = share.submit = share.share = 0
91 
92 		share.save()
93 
94 		if not (share.read or share.write or share.submit or share.share):
95 			share.delete()
96 			share = {}
97 
98 	return share
99 
100 
101 @frappe.whitelist()
102 def get_users(doctype, name):
103 	"""Get list of users with which this document is shared"""
104 	return frappe.db.get_all(
105 		"DocShare",
106 		fields=[
107 			"`name`",
108 			"`user`",
109 			"`read`",
110 			"`write`",
111 			"`submit`",
112 			"`share`",
113 			"everyone",
114 			"owner",
115 			"creation",
116 		],
117 		filters=dict(share_doctype=doctype, share_name=name),
118 	)
119 
120 
121 def get_shared(doctype, user=None, rights=None):
122 	"""Get list of shared document names for given user and DocType.
123 
124 	:param doctype: DocType of which shared names are queried.
125 	:param user: User for which shared names are queried.
126 	:param rights: List of rights for which the document is shared. List of `read`, `write`, `share`"""
127 
128 	if not user:
129 		user = frappe.session.user
130 
131 	if not rights:
132 		rights = ["read"]
133 
134 	filters = [[right, "=", 1] for right in rights]
135 	filters += [["share_doctype", "=", doctype]]
136 	or_filters = [["user", "=", user]]
137 	if user != "Guest":
138 		or_filters += [["everyone", "=", 1]]
139 
140 	shared_docs = frappe.db.get_all(
141 		"DocShare", fields=["share_name"], filters=filters, or_filters=or_filters
142 	)
143 
144 	return [doc.share_name for doc in shared_docs]
145 
146 
147 def get_shared_doctypes(user=None):
148 	"""Return list of doctypes in which documents are shared for the given user."""
149 	if not user:
150 		user = frappe.session.user
151 	table = frappe.qb.DocType("DocShare")
152 	query = (
153 		frappe.qb.from_(table)
154 		.where((table.user == user) | (table.everyone == 1))
155 		.select(table.share_doctype)
156 		.distinct()
157 	)
158 	return query.run(pluck=True)
159 
160 
161 def get_share_name(doctype, name, user, everyone):
162 	if cint(everyone):
163 		share_name = frappe.db.get_value(
164 			"DocShare", {"everyone": 1, "share_name": name, "share_doctype": doctype}
165 		)
166 	else:
167 		share_name = frappe.db.get_value(
168 			"DocShare", {"user": user, "share_name": name, "share_doctype": doctype}
169 		)
170 
171 	return share_name
172 
173 
174 def check_share_permission(doctype, name):
175 	"""Check if the user can share with other users"""
176 	if not frappe.has_permission(doctype, ptype="share", doc=name):
177 		frappe.throw(
178 			_("No permission to {0} {1} {2}").format("share", doctype, name), frappe.PermissionError
179 		)
180 
181 
182 def notify_assignment(shared_by, doctype, doc_name, everyone, notify=0):
183 
184 	if not (shared_by and doctype and doc_name) or everyone or not notify:
185 		return
186 
187 	from frappe.utils import get_fullname
188 
189 	title = get_title(doctype, doc_name)
190 
191 	reference_user = get_fullname(frappe.session.user)
192 	notification_message = _("{0} shared a document {1} {2} with you").format(
193 		frappe.bold(reference_user), frappe.bold(doctype), get_title_html(title)
194 	)
195 
196 	notification_doc = {
197 		"type": "Share",
198 		"document_type": doctype,
199 		"subject": notification_message,
200 		"document_name": doc_name,
201 		"from_user": frappe.session.user,
202 	}
203 
204 	enqueue_create_notification(shared_by, notification_doc)
205
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/frappe/share.py b/frappe/share.py
--- a/frappe/share.py
+++ b/frappe/share.py
@@ -93,7 +93,7 @@
 
 		if not (share.read or share.write or share.submit or share.share):
 			share.delete()
-			share = {}
+			share = None
 
 	return share

{"golden_diff": "diff --git a/frappe/share.py b/frappe/share.py\n--- a/frappe/share.py\n+++ b/frappe/share.py\n@@ -93,7 +93,7 @@\n \n \t\tif not (share.read or share.write or share.submit or share.share):\n \t\t\tshare.delete()\n-\t\t\tshare = {}\n+\t\t\tshare = None\n \n \treturn share\n", "issue": "Remove Share doesn't disappear \n## Description of the issue\r\nWhen the read Permission of a Share is removed by de-selecting the checkbox, then the corresponding DocShare is removed in the Backend, but the checkbox is automatically re-selected in the frontend. After a refresh, the share \r\n\r\n\r\n## Context information (for bug reports)\r\n\r\n**Output of `bench version`**\r\n```\r\nfrappe 14.x.x-develop\r\n```\r\n\r\n## Steps to reproduce the issue\r\n\r\n1. Open an arbitrary Document\r\n2. Add a share with read permissions\r\n3. Remove the read permission by clicking the checkbox\r\n\r\n### Observed result\r\nThe checkbox is automatically re-selected\r\n\r\n### Expected result\r\nThe share entry disappears\r\n\r\n## Additional information\r\n\r\n\n", "before_files": [{"content": "# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n# License: MIT. See LICENSE\n\nimport frappe\nfrom frappe import _\nfrom frappe.desk.doctype.notification_log.notification_log import (\n\tenqueue_create_notification,\n\tget_title,\n\tget_title_html,\n)\nfrom frappe.desk.form.document_follow import follow_document\nfrom frappe.utils import cint\n\n\n@frappe.whitelist()\ndef add(\n\tdoctype, name, user=None, read=1, write=0, submit=0, share=0, everyone=0, flags=None, notify=0\n):\n\t\"\"\"Share the given document with a user.\"\"\"\n\tif not user:\n\t\tuser = frappe.session.user\n\n\tif not (flags or {}).get(\"ignore_share_permission\"):\n\t\tcheck_share_permission(doctype, name)\n\n\tshare_name = get_share_name(doctype, name, user, everyone)\n\n\tif share_name:\n\t\tdoc = frappe.get_doc(\"DocShare\", share_name)\n\telse:\n\t\tdoc = frappe.new_doc(\"DocShare\")\n\t\tdoc.update(\n\t\t\t{\"user\": user, \"share_doctype\": doctype, \"share_name\": name, \"everyone\": cint(everyone)}\n\t\t)\n\n\tif flags:\n\t\tdoc.flags.update(flags)\n\n\tdoc.update(\n\t\t{\n\t\t\t# always add read, since you are adding!\n\t\t\t\"read\": 1,\n\t\t\t\"write\": cint(write),\n\t\t\t\"submit\": cint(submit),\n\t\t\t\"share\": cint(share),\n\t\t}\n\t)\n\n\tdoc.save(ignore_permissions=True)\n\tnotify_assignment(user, doctype, name, everyone, notify=notify)\n\n\tif frappe.get_cached_value(\"User\", user, \"follow_shared_documents\"):\n\t\tfollow_document(doctype, name, user)\n\n\treturn doc\n\n\ndef remove(doctype, name, user, flags=None):\n\tshare_name = frappe.db.get_value(\n\t\t\"DocShare\", {\"user\": user, \"share_name\": name, \"share_doctype\": doctype}\n\t)\n\n\tif share_name:\n\t\tfrappe.delete_doc(\"DocShare\", share_name, flags=flags)\n\n\n@frappe.whitelist()\ndef set_permission(doctype, name, user, permission_to, value=1, everyone=0):\n\t\"\"\"Set share permission.\"\"\"\n\tcheck_share_permission(doctype, name)\n\n\tshare_name = get_share_name(doctype, name, user, everyone)\n\tvalue = int(value)\n\n\tif not share_name:\n\t\tif value:\n\t\t\tshare = add(doctype, name, user, everyone=everyone, **{permission_to: 1})\n\t\telse:\n\t\t\t# no share found, nothing to remove\n\t\t\tshare = {}\n\t\t\tpass\n\telse:\n\t\tshare = frappe.get_doc(\"DocShare\", share_name)\n\t\tshare.flags.ignore_permissions = True\n\t\tshare.set(permission_to, value)\n\n\t\tif not value:\n\t\t\t# un-set higher-order permissions too\n\t\t\tif permission_to == \"read\":\n\t\t\t\tshare.read = share.write = share.submit = share.share = 0\n\n\t\tshare.save()\n\n\t\tif not (share.read or share.write or share.submit or share.share):\n\t\t\tshare.delete()\n\t\t\tshare = {}\n\n\treturn share\n\n\n@frappe.whitelist()\ndef get_users(doctype, name):\n\t\"\"\"Get list of users with which this document is shared\"\"\"\n\treturn frappe.db.get_all(\n\t\t\"DocShare\",\n\t\tfields=[\n\t\t\t\"`name`\",\n\t\t\t\"`user`\",\n\t\t\t\"`read`\",\n\t\t\t\"`write`\",\n\t\t\t\"`submit`\",\n\t\t\t\"`share`\",\n\t\t\t\"everyone\",\n\t\t\t\"owner\",\n\t\t\t\"creation\",\n\t\t],\n\t\tfilters=dict(share_doctype=doctype, share_name=name),\n\t)\n\n\ndef get_shared(doctype, user=None, rights=None):\n\t\"\"\"Get list of shared document names for given user and DocType.\n\n\t:param doctype: DocType of which shared names are queried.\n\t:param user: User for which shared names are queried.\n\t:param rights: List of rights for which the document is shared. List of `read`, `write`, `share`\"\"\"\n\n\tif not user:\n\t\tuser = frappe.session.user\n\n\tif not rights:\n\t\trights = [\"read\"]\n\n\tfilters = [[right, \"=\", 1] for right in rights]\n\tfilters += [[\"share_doctype\", \"=\", doctype]]\n\tor_filters = [[\"user\", \"=\", user]]\n\tif user != \"Guest\":\n\t\tor_filters += [[\"everyone\", \"=\", 1]]\n\n\tshared_docs = frappe.db.get_all(\n\t\t\"DocShare\", fields=[\"share_name\"], filters=filters, or_filters=or_filters\n\t)\n\n\treturn [doc.share_name for doc in shared_docs]\n\n\ndef get_shared_doctypes(user=None):\n\t\"\"\"Return list of doctypes in which documents are shared for the given user.\"\"\"\n\tif not user:\n\t\tuser = frappe.session.user\n\ttable = frappe.qb.DocType(\"DocShare\")\n\tquery = (\n\t\tfrappe.qb.from_(table)\n\t\t.where((table.user == user) | (table.everyone == 1))\n\t\t.select(table.share_doctype)\n\t\t.distinct()\n\t)\n\treturn query.run(pluck=True)\n\n\ndef get_share_name(doctype, name, user, everyone):\n\tif cint(everyone):\n\t\tshare_name = frappe.db.get_value(\n\t\t\t\"DocShare\", {\"everyone\": 1, \"share_name\": name, \"share_doctype\": doctype}\n\t\t)\n\telse:\n\t\tshare_name = frappe.db.get_value(\n\t\t\t\"DocShare\", {\"user\": user, \"share_name\": name, \"share_doctype\": doctype}\n\t\t)\n\n\treturn share_name\n\n\ndef check_share_permission(doctype, name):\n\t\"\"\"Check if the user can share with other users\"\"\"\n\tif not frappe.has_permission(doctype, ptype=\"share\", doc=name):\n\t\tfrappe.throw(\n\t\t\t_(\"No permission to {0} {1} {2}\").format(\"share\", doctype, name), frappe.PermissionError\n\t\t)\n\n\ndef notify_assignment(shared_by, doctype, doc_name, everyone, notify=0):\n\n\tif not (shared_by and doctype and doc_name) or everyone or not notify:\n\t\treturn\n\n\tfrom frappe.utils import get_fullname\n\n\ttitle = get_title(doctype, doc_name)\n\n\treference_user = get_fullname(frappe.session.user)\n\tnotification_message = _(\"{0} shared a document {1} {2} with you\").format(\n\t\tfrappe.bold(reference_user), frappe.bold(doctype), get_title_html(title)\n\t)\n\n\tnotification_doc = {\n\t\t\"type\": \"Share\",\n\t\t\"document_type\": doctype,\n\t\t\"subject\": notification_message,\n\t\t\"document_name\": doc_name,\n\t\t\"from_user\": frappe.session.user,\n\t}\n\n\tenqueue_create_notification(shared_by, notification_doc)\n", "path": "frappe/share.py"}], "after_files": [{"content": "# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n# License: MIT. See LICENSE\n\nimport frappe\nfrom frappe import _\nfrom frappe.desk.doctype.notification_log.notification_log import (\n\tenqueue_create_notification,\n\tget_title,\n\tget_title_html,\n)\nfrom frappe.desk.form.document_follow import follow_document\nfrom frappe.utils import cint\n\n\n@frappe.whitelist()\ndef add(\n\tdoctype, name, user=None, read=1, write=0, submit=0, share=0, everyone=0, flags=None, notify=0\n):\n\t\"\"\"Share the given document with a user.\"\"\"\n\tif not user:\n\t\tuser = frappe.session.user\n\n\tif not (flags or {}).get(\"ignore_share_permission\"):\n\t\tcheck_share_permission(doctype, name)\n\n\tshare_name = get_share_name(doctype, name, user, everyone)\n\n\tif share_name:\n\t\tdoc = frappe.get_doc(\"DocShare\", share_name)\n\telse:\n\t\tdoc = frappe.new_doc(\"DocShare\")\n\t\tdoc.update(\n\t\t\t{\"user\": user, \"share_doctype\": doctype, \"share_name\": name, \"everyone\": cint(everyone)}\n\t\t)\n\n\tif flags:\n\t\tdoc.flags.update(flags)\n\n\tdoc.update(\n\t\t{\n\t\t\t# always add read, since you are adding!\n\t\t\t\"read\": 1,\n\t\t\t\"write\": cint(write),\n\t\t\t\"submit\": cint(submit),\n\t\t\t\"share\": cint(share),\n\t\t}\n\t)\n\n\tdoc.save(ignore_permissions=True)\n\tnotify_assignment(user, doctype, name, everyone, notify=notify)\n\n\tif frappe.get_cached_value(\"User\", user, \"follow_shared_documents\"):\n\t\tfollow_document(doctype, name, user)\n\n\treturn doc\n\n\ndef remove(doctype, name, user, flags=None):\n\tshare_name = frappe.db.get_value(\n\t\t\"DocShare\", {\"user\": user, \"share_name\": name, \"share_doctype\": doctype}\n\t)\n\n\tif share_name:\n\t\tfrappe.delete_doc(\"DocShare\", share_name, flags=flags)\n\n\n@frappe.whitelist()\ndef set_permission(doctype, name, user, permission_to, value=1, everyone=0):\n\t\"\"\"Set share permission.\"\"\"\n\tcheck_share_permission(doctype, name)\n\n\tshare_name = get_share_name(doctype, name, user, everyone)\n\tvalue = int(value)\n\n\tif not share_name:\n\t\tif value:\n\t\t\tshare = add(doctype, name, user, everyone=everyone, **{permission_to: 1})\n\t\telse:\n\t\t\t# no share found, nothing to remove\n\t\t\tshare = {}\n\t\t\tpass\n\telse:\n\t\tshare = frappe.get_doc(\"DocShare\", share_name)\n\t\tshare.flags.ignore_permissions = True\n\t\tshare.set(permission_to, value)\n\n\t\tif not value:\n\t\t\t# un-set higher-order permissions too\n\t\t\tif permission_to == \"read\":\n\t\t\t\tshare.read = share.write = share.submit = share.share = 0\n\n\t\tshare.save()\n\n\t\tif not (share.read or share.write or share.submit or share.share):\n\t\t\tshare.delete()\n\t\t\tshare = None\n\n\treturn share\n\n\n@frappe.whitelist()\ndef get_users(doctype, name):\n\t\"\"\"Get list of users with which this document is shared\"\"\"\n\treturn frappe.db.get_all(\n\t\t\"DocShare\",\n\t\tfields=[\n\t\t\t\"`name`\",\n\t\t\t\"`user`\",\n\t\t\t\"`read`\",\n\t\t\t\"`write`\",\n\t\t\t\"`submit`\",\n\t\t\t\"`share`\",\n\t\t\t\"everyone\",\n\t\t\t\"owner\",\n\t\t\t\"creation\",\n\t\t],\n\t\tfilters=dict(share_doctype=doctype, share_name=name),\n\t)\n\n\ndef get_shared(doctype, user=None, rights=None):\n\t\"\"\"Get list of shared document names for given user and DocType.\n\n\t:param doctype: DocType of which shared names are queried.\n\t:param user: User for which shared names are queried.\n\t:param rights: List of rights for which the document is shared. List of `read`, `write`, `share`\"\"\"\n\n\tif not user:\n\t\tuser = frappe.session.user\n\n\tif not rights:\n\t\trights = [\"read\"]\n\n\tfilters = [[right, \"=\", 1] for right in rights]\n\tfilters += [[\"share_doctype\", \"=\", doctype]]\n\tor_filters = [[\"user\", \"=\", user]]\n\tif user != \"Guest\":\n\t\tor_filters += [[\"everyone\", \"=\", 1]]\n\n\tshared_docs = frappe.db.get_all(\n\t\t\"DocShare\", fields=[\"share_name\"], filters=filters, or_filters=or_filters\n\t)\n\n\treturn [doc.share_name for doc in shared_docs]\n\n\ndef get_shared_doctypes(user=None):\n\t\"\"\"Return list of doctypes in which documents are shared for the given user.\"\"\"\n\tif not user:\n\t\tuser = frappe.session.user\n\ttable = frappe.qb.DocType(\"DocShare\")\n\tquery = (\n\t\tfrappe.qb.from_(table)\n\t\t.where((table.user == user) | (table.everyone == 1))\n\t\t.select(table.share_doctype)\n\t\t.distinct()\n\t)\n\treturn query.run(pluck=True)\n\n\ndef get_share_name(doctype, name, user, everyone):\n\tif cint(everyone):\n\t\tshare_name = frappe.db.get_value(\n\t\t\t\"DocShare\", {\"everyone\": 1, \"share_name\": name, \"share_doctype\": doctype}\n\t\t)\n\telse:\n\t\tshare_name = frappe.db.get_value(\n\t\t\t\"DocShare\", {\"user\": user, \"share_name\": name, \"share_doctype\": doctype}\n\t\t)\n\n\treturn share_name\n\n\ndef check_share_permission(doctype, name):\n\t\"\"\"Check if the user can share with other users\"\"\"\n\tif not frappe.has_permission(doctype, ptype=\"share\", doc=name):\n\t\tfrappe.throw(\n\t\t\t_(\"No permission to {0} {1} {2}\").format(\"share\", doctype, name), frappe.PermissionError\n\t\t)\n\n\ndef notify_assignment(shared_by, doctype, doc_name, everyone, notify=0):\n\n\tif not (shared_by and doctype and doc_name) or everyone or not notify:\n\t\treturn\n\n\tfrom frappe.utils import get_fullname\n\n\ttitle = get_title(doctype, doc_name)\n\n\treference_user = get_fullname(frappe.session.user)\n\tnotification_message = _(\"{0} shared a document {1} {2} with you\").format(\n\t\tfrappe.bold(reference_user), frappe.bold(doctype), get_title_html(title)\n\t)\n\n\tnotification_doc = {\n\t\t\"type\": \"Share\",\n\t\t\"document_type\": doctype,\n\t\t\"subject\": notification_message,\n\t\t\"document_name\": doc_name,\n\t\t\"from_user\": frappe.session.user,\n\t}\n\n\tenqueue_create_notification(shared_by, notification_doc)\n", "path": "frappe/share.py"}]}