internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: frappe/frappe

Issue:
Problems while using translations via Globe Symbol 
## Description / Context information (for bug reports)

There are 2 issues - 

**Issue - 1** 
While updating translations using Globe Symbol, system generates duplicate rows of translations for records added in Description 


https://user-images.githubusercontent.com/16986940/132095963-9b747145-cdb8-4972-8cd9-e2dc907b45a3.mp4


<hr/>

**Issue - 2**
When clicking on the globe button of Item-2, values from the prev edited item (Item-1) are displayed.In order to refresh the correct values of Item-2, page reload is required.

https://user-images.githubusercontent.com/16986940/132095967-caefab6a-ff84-45dc-b1ad-50a0ba60e84f.mp4


**Output of `bench version`**

We Checked on version-12 and version-13
Problem is consistent for versions

```
Bench 5.5.0
ERPNext: v13.10.0 (version-13)
Frappe Framework: v13.10.0 (version-13)
```

```
Bench 5.5.0
ERPNext: v12.23.0 (version-12)
Frappe Framework: v12.20.0 (version-12)
```


## Steps to reproduce the issue

Check Translate On Description field for Item master.

<hr/>

- vamagithub@gmail.com 
- seanthankur20@gmail.com



Discussion:

Resolving patch:
diff --git a/frappe/translate.py b/frappe/translate.py
--- a/frappe/translate.py
+++ b/frappe/translate.py
@@ -766,7 +766,10 @@ def update_translations_for_source(source=None, translation_dict=None):
 		return
 
 	translation_dict = json.loads(translation_dict)
-
+	
+	if is_html(source):
+		source = strip_html_tags(source)
+	
 	# for existing records
 	translation_records = frappe.db.get_values('Translation', { 'source_name': source }, ['name', 'language'],  as_dict=1)
 	for d in translation_records:


Test patch:
Repository: frappe/frappe

Issue:
frappe.db.exists is not available to Server Scripts
**Is your feature request related to a problem? Please describe.**
`frappe.db.exists` is not exposed to **Server Scripts**.

**Describe alternatives you've considered**
Currently I am using `frappe.get_all` with `filters` and `limit=1` to check for existence.



Discussion:

Resolving patch:
diff --git a/frappe/utils/safe_exec.py b/frappe/utils/safe_exec.py
--- a/frappe/utils/safe_exec.py
+++ b/frappe/utils/safe_exec.py
@@ -147,6 +147,7 @@ def get_safe_globals():
 			set_value = frappe.db.set_value,
 			get_single_value = frappe.db.get_single_value,
 			get_default = frappe.db.get_default,
+			exists = frappe.db.exists,
 			count = frappe.db.count,
 			min = frappe.db.min,
 			max = frappe.db.max,


Test patch:
Repository: frappe/frappe

Issue:
imaplib error when fetching emails
When someone tried to pull emails from their account (using IMAP server), they encountered this error

<img width="633" alt="Screenshot 2021-12-21 at 10 44 51 AM" src="https://user-images.githubusercontent.com/58825865/146875998-ade6c090-2a5c-4000-ab94-64a24d0cf88f.png">

The same issue was raised when we had the limit 100k(which is default)  and was overridden  in this PR #6751
<img width="674" alt="Screenshot 2021-12-21 at 11 04 00 AM" src="https://user-images.githubusercontent.com/58825865/146876789-8f320da0-00d4-452a-9253-6ea9e834c147.png">÷

Do we have to keep increasing the limit every time we face the issue? Or there is another possible solution?
[Refer this](https://stackoverflow.com/questions/25457441/reading-emails-with-imaplib-got-more-than-10000-bytes-error)

@surajshetty3416 @gavindsouza


Discussion:
In the imaplib's [source](https://github.com/python/cpython/blob/main/Lib/imaplib.py#L53) they have the `_MAXLINE` set as 100k bytes by default (written in the source that it used to be 10k but then they bumped it up) - so we're using it by reducing the bytes 😄 

![Screenshot 2021-12-21 at 12 46 56 PM](https://user-images.githubusercontent.com/32034600/146887795-32dba5cc-fb39-486e-b0f2-c6f11066d027.png)

The poplib line does increase the limit, however the imaplib line reduces it. I'm not certain what the reasons were to reduce the 1M limit, the commit message isn't very specific. If we don't have the knowledge of why this change was made, maybe we can get rid of it now 🤔. 

* The poplib limit was added ~6 years ago via https://github.com/frappe/frappe/commit/0ace93a984aff0f59c87b72a5e0ef786bec403c0. 
* The imaplib limit however seems more recent, ~2 years ago via https://github.com/frappe/frappe/commit/59549eb9df2efdd899d11b24fb934991afd331b1.

---

cc: @rohitwaghchaure @saurabh6790 
If _MAXLINE = 1000000 was there earlier then how it was broken earlier?
We can remove the code which I had added and check.

Resolving patch:
diff --git a/frappe/email/receive.py b/frappe/email/receive.py
--- a/frappe/email/receive.py
+++ b/frappe/email/receive.py
@@ -27,11 +27,7 @@
 
 # fix due to a python bug in poplib that limits it to 2048
 poplib._MAXLINE = 20480
-imaplib._MAXLINE = 20480
 
-# fix due to a python bug in poplib that limits it to 2048
-poplib._MAXLINE = 20480
-imaplib._MAXLINE = 20480
 
 
 class EmailSizeExceededError(frappe.ValidationError): pass


Test patch:
Repository: frappe/frappe

Issue:
no_copy option not available in customize form field
<!--
Welcome to the Frappe Framework issue tracker! Before creating an issue, please heed the following:

1. This tracker should only be used to report bugs and request features / enhancements to Frappe
    - For questions and general support, use https://stackoverflow.com/questions/tagged/frappe
    - For documentation issues, refer to https://frappeframework.com/docs/user/en or the developer cheetsheet https://github.com/frappe/frappe/wiki/Developer-Cheatsheet
2. Use the search function before creating a new issue. Duplicates will be closed and directed to
   the original discussion.
3. When making a bug report, make sure you provide all required information. The easier it is for
   maintainers to reproduce, the faster it'll be fixed.
4. If you think you know what the reason for the bug is, share it with us. Maybe put in a PR 😉
-->

## Description of the issue

## Context information (for bug reports)

**Output of `bench version`**
```
(paste here)
```

## Steps to reproduce the issue

1.
2.
3.

### Observed result
no copy is a field property in doctype, but in customize form, the no copy option is not available for the field. 

### Expected result
make no copy as available property of the field in customize form 
### Stacktrace / full error message

```
(paste here)
```

## Additional information

OS version / distribution, `Frappe` install method, etc.



Discussion:

Resolving patch:
diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py
--- a/frappe/custom/doctype/customize_form/customize_form.py
+++ b/frappe/custom/doctype/customize_form/customize_form.py
@@ -540,6 +540,7 @@ def reset_customization(doctype):
 	'in_global_search': 'Check',
 	'in_preview': 'Check',
 	'bold': 'Check',
+	'no_copy': 'Check',
 	'hidden': 'Check',
 	'collapsible': 'Check',
 	'collapsible_depends_on': 'Data',


Test patch:
diff --git a/frappe/custom/doctype/customize_form/test_customize_form.py b/frappe/custom/doctype/customize_form/test_customize_form.py
--- a/frappe/custom/doctype/customize_form/test_customize_form.py
+++ b/frappe/custom/doctype/customize_form/test_customize_form.py
@@ -97,13 +97,18 @@ def test_save_customization_custom_field_property(self):
 
 		custom_field = d.get("fields", {"fieldname": "test_custom_field"})[0]
 		custom_field.reqd = 1
+		custom_field.no_copy = 1
 		d.run_method("save_customization")
 		self.assertEqual(frappe.db.get_value("Custom Field", "Event-test_custom_field", "reqd"), 1)
+		self.assertEqual(frappe.db.get_value("Custom Field", "Event-test_custom_field", "no_copy"), 1)
 
 		custom_field = d.get("fields", {"is_custom_field": True})[0]
 		custom_field.reqd = 0
+		custom_field.no_copy = 0
 		d.run_method("save_customization")
 		self.assertEqual(frappe.db.get_value("Custom Field", "Event-test_custom_field", "reqd"), 0)
+		self.assertEqual(frappe.db.get_value("Custom Field", "Event-test_custom_field", "no_copy"), 0)
+
 
 	def test_save_customization_new_field(self):
 		d = self.get_customize_form("Event")
Repository: frappe/frappe

Issue:
'Logout' -> 'Log out'
To “log out” (two separate words) is to take action, while “logout” is a noun or adjective that describes the components required to exit an account. It is a small difference, but clear grammar is a cornerstone of clear UX.

![CleanShot 2022-03-24 at 15 17 11@2x](https://user-images.githubusercontent.com/46772424/159891494-773a7e55-b7cc-4b97-9372-c60642098526.png)



Discussion:

Resolving patch:
diff --git a/frappe/commands/site.py b/frappe/commands/site.py
--- a/frappe/commands/site.py
+++ b/frappe/commands/site.py
@@ -728,7 +728,7 @@ def move(dest_dir, site):
 @click.command('set-password')
 @click.argument('user')
 @click.argument('password', required=False)
-@click.option('--logout-all-sessions', help='Logout from all sessions', is_flag=True, default=False)
+@click.option('--logout-all-sessions', help='Log out from all sessions', is_flag=True, default=False)
 @pass_context
 def set_password(context, user, password=None, logout_all_sessions=False):
 	"Set password for a user on a site"
@@ -741,7 +741,7 @@ def set_password(context, user, password=None, logout_all_sessions=False):
 
 @click.command('set-admin-password')
 @click.argument('admin-password', required=False)
-@click.option('--logout-all-sessions', help='Logout from all sessions', is_flag=True, default=False)
+@click.option('--logout-all-sessions', help='Log out from all sessions', is_flag=True, default=False)
 @pass_context
 def set_admin_password(context, admin_password=None, logout_all_sessions=False):
 	"Set Administrator password for a site"
diff --git a/frappe/utils/install.py b/frappe/utils/install.py
--- a/frappe/utils/install.py
+++ b/frappe/utils/install.py
@@ -236,7 +236,7 @@ def add_standard_navbar_items():
 			'is_standard': 1
 		},
 		{
-			'item_label': 'Logout',
+			'item_label': 'Log out',
 			'item_type': 'Action',
 			'action': 'frappe.app.logout()',
 			'is_standard': 1
diff --git a/frappe/website/doctype/website_settings/website_settings.py b/frappe/website/doctype/website_settings/website_settings.py
--- a/frappe/website/doctype/website_settings/website_settings.py
+++ b/frappe/website/doctype/website_settings/website_settings.py
@@ -111,7 +111,7 @@ def get_website_settings(context=None):
 		'footer_items': get_items('footer_items'),
 		"post_login": [
 			{"label": _("My Account"), "url": "/me"},
-			{"label": _("Logout"), "url": "/?cmd=web_logout"}
+			{"label": _("Log out"), "url": "/?cmd=web_logout"}
 		]
 	})
 


Test patch:
Repository: frappe/frappe

Issue:
"expand all" not working on treeviews
Doens't work on warehouse, just removes full tree. 
<img width="1373" alt="Screenshot 2022-05-26 at 6 07 52 PM" src="https://user-images.githubusercontent.com/9079960/170489271-6c0400fc-2872-44b7-a58b-3fd9d2a11f1e.png">


Doesn't work on the account tree too

<img width="1373" alt="Screenshot 2022-05-26 at 6 07 44 PM" src="https://user-images.githubusercontent.com/9079960/170489256-ecf9cb9d-d38f-421c-a3d4-97ae9779bb0c.png">


affects: develop


Discussion:

Resolving patch:
diff --git a/frappe/__init__.py b/frappe/__init__.py
--- a/frappe/__init__.py
+++ b/frappe/__init__.py
@@ -1501,18 +1501,26 @@ def call(fn, *args, **kwargs):
 
 
 def get_newargs(fn, kwargs):
+
+	# if function has any **kwargs parameter that capture arbitrary keyword arguments
+	# Ref: https://docs.python.org/3/library/inspect.html#inspect.Parameter.kind
+	varkw_exist = False
+
 	if hasattr(fn, "fnargs"):
 		fnargs = fn.fnargs
 	else:
 		signature = inspect.signature(fn)
 		fnargs = list(signature.parameters)
-		varkw = "kwargs" in fnargs
-		if varkw:
-			fnargs.pop(-1)
+
+		for param_name, parameter in signature.parameters.items():
+			if parameter.kind == inspect.Parameter.VAR_KEYWORD:
+				varkw_exist = True
+				fnargs.remove(param_name)
+				break
 
 	newargs = {}
 	for a in kwargs:
-		if (a in fnargs) or varkw:
+		if (a in fnargs) or varkw_exist:
 			newargs[a] = kwargs.get(a)
 
 	newargs.pop("ignore_permissions", None)


Test patch:
diff --git a/frappe/tests/test_utils.py b/frappe/tests/test_utils.py
--- a/frappe/tests/test_utils.py
+++ b/frappe/tests/test_utils.py
@@ -615,3 +615,29 @@ def test_app_name_parser(self):
 		self.assertEqual("healthcare", parse_app_name("https://github.com/frappe/healthcare.git"))
 		self.assertEqual("healthcare", parse_app_name("git@github.com:frappe/healthcare.git"))
 		self.assertEqual("healthcare", parse_app_name("frappe/healthcare@develop"))
+
+
+class TestIntrospectionMagic(unittest.TestCase):
+	"""Test utils that inspect live objects"""
+
+	def test_get_newargs(self):
+		# `kwargs` is just convention any **varname should work.
+		def f(a, b=2, **args):
+			pass
+
+		safe_kwargs = {"company": "Wind Power", "b": 1}
+		self.assertEqual(frappe.get_newargs(f, safe_kwargs), safe_kwargs)
+
+		unsafe_args = dict(safe_kwargs)
+		unsafe_args.update({"ignore_permissions": True, "flags": {"ignore_mandatory": True}})
+		self.assertEqual(frappe.get_newargs(f, unsafe_args), safe_kwargs)
+
+	def test_strip_off_kwargs_when_not_supported(self):
+		def f(a, b=2):
+			pass
+
+		args = {"company": "Wind Power", "b": 1}
+		self.assertEqual(frappe.get_newargs(f, args), {"b": 1})
+
+		# No args
+		self.assertEqual(frappe.get_newargs(lambda: None, args), {})
Repository: frappe/frappe

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




Discussion:

Resolving patch:
diff --git a/frappe/share.py b/frappe/share.py
--- a/frappe/share.py
+++ b/frappe/share.py
@@ -93,7 +93,7 @@ def set_permission(doctype, name, user, permission_to, value=1, everyone=0):
 
 		if not (share.read or share.write or share.submit or share.share):
 			share.delete()
-			share = {}
+			share = None
 
 	return share
 


Test patch:
Repository: frappe/frappe

Issue:
The fieldname you've specified in Attached To Field is invalid
After upgrading to Frappe v14.16.0, I'm getting the error `The fieldname you've specified in Attached To Field is invalid` when I try to attach an image to a child table in my custom app.


Discussion:
Same error.
![image](https://user-images.githubusercontent.com/1822868/204457696-066d11ba-83a9-4954-bd94-dfc57801d45c.png)

@sagarvora any fix for this? Seems to be caused by this commit https://github.com/frappe/frappe/commit/5fe9f3cb5e955dd9c652c77daf2334cbb940f9f6
I'm working on a fix.

Resolving patch:
diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py
--- a/frappe/core/doctype/file/file.py
+++ b/frappe/core/doctype/file/file.py
@@ -14,6 +14,7 @@
 
 import frappe
 from frappe import _
+from frappe.database.schema import SPECIAL_CHAR_PATTERN
 from frappe.model.document import Document
 from frappe.utils import call_hook_method, cint, get_files_path, get_hook_method, get_url
 from frappe.utils.file_manager import is_safe_path
@@ -104,10 +105,7 @@ def validate_attachment_references(self):
 		if not self.attached_to_name or not isinstance(self.attached_to_name, (str, int)):
 			frappe.throw(_("Attached To Name must be a string or an integer"), frappe.ValidationError)
 
-		if not self.attached_to_field:
-			return
-
-		if not frappe.get_meta(self.attached_to_doctype).has_field(self.attached_to_field):
+		if self.attached_to_field and SPECIAL_CHAR_PATTERN.search(self.attached_to_field):
 			frappe.throw(_("The fieldname you've specified in Attached To Field is invalid"))
 
 	def after_rename(self, *args, **kwargs):


Test patch:
Repository: frappe/frappe

Issue:
TypeError: unhashable type: 'list' when using frappe.throw() or frappe.msgprint()
## Description of the issue
When using `frappe.throw(..., as_list=True)` to show a list of errors, python throws a TypeError: unhashable type: 'list' exception.
The same happens when using `frappe.msgprint(..., as_list=True)`

## Context information (for bug reports)
Example block code:
```
error_list = []
for item in self.get_item_docs():
    msg = _(
        "Item #{}: <strong>SAT Product or Service Key</strong> is missing from item {}"
    ).format(item.idx + 1, frappe.bold(item.name))

    if not item.sat_product_or_service_key:
        error_list.append(msg)

frappe.throw(
    error_list,
    title=_("Invalid Product or Service Key"),
    as_list=True,
)
```

**Output of `bench version`**
```
erpnext 14.10.0
frappe 14.18.1
```

### Stacktrace / full error message
This is the complete exception output :
```
File ~/Repos/frappe-bench/apps/frappe/frappe/__init__.py:457, in msgprint(msg, title, raise_exception, as_table, as_list, indicator, alert, primary_action, is_minimizable, wide)
    454         out.as_list = 1
    456 if sys.stdin and sys.stdin.isatty():
--> 457         msg = _strip_html_tags(out.message)
    459 if flags.print_messages and out.message:
    460         print(f"Message: {_strip_html_tags(out.message)}")

TypeError: unhashable type: 'list'
```

## Additional information
OS: Manjaro Linux x86_64 
Kernel: 6.0.11-1-MANJARO
Manual Frappe Installation (repo build)




Discussion:

Resolving patch:
diff --git a/frappe/__init__.py b/frappe/__init__.py
--- a/frappe/__init__.py
+++ b/frappe/__init__.py
@@ -453,7 +453,10 @@ def _raise_exception():
 		out.as_list = 1
 
 	if sys.stdin and sys.stdin.isatty():
-		msg = _strip_html_tags(out.message)
+		if out.as_list:
+			msg = [_strip_html_tags(msg) for msg in out.message]
+		else:
+			msg = _strip_html_tags(out.message)
 
 	if flags.print_messages and out.message:
 		print(f"Message: {_strip_html_tags(out.message)}")


Test patch:
Repository: frappe/frappe

Issue:
bug: Google Drive backup file names malformed
## Description of the issue

The files are uploaded with the full file path as the file name.
This makes extracting and restoring the files difficult.

![Screen Shot 2022-03-01 at 16 49 56](https://user-images.githubusercontent.com/64409021/156212763-43172946-6f0a-41ae-add4-9fb56fc21edd.png)

## Context information (for bug reports)

**Output of `bench version`**
```
ERPNext: v13.19.0
Frappe Framework: v13.19.0
```

## Steps to reproduce the issue

1. Back up to Google Drive

### Observed result
Malformed file names

### Expected result
Normal file names



Discussion:
I've got the same issue. Any progress on this?

Resolving patch:
diff --git a/frappe/integrations/doctype/google_drive/google_drive.py b/frappe/integrations/doctype/google_drive/google_drive.py
--- a/frappe/integrations/doctype/google_drive/google_drive.py
+++ b/frappe/integrations/doctype/google_drive/google_drive.py
@@ -169,7 +169,7 @@ def upload_system_backup_to_google_drive():
 		if not fileurl:
 			continue
 
-		file_metadata = {"name": fileurl, "parents": [account.backup_folder_id]}
+		file_metadata = {"name": os.path.basename(fileurl), "parents": [account.backup_folder_id]}
 
 		try:
 			media = MediaFileUpload(


Test patch:
Repository: frappe/frappe

Issue:
Onload run before permissions checking
In frappe/desk/load.py, we have:

```frappe.whitelist()
def getdoc(doctype, name, user=None):
	"""
	Loads a doclist for a given document. This method is called directly from the client.
	Requries "doctype", "name" as form variables.
	Will also call the "onload" method on the document.
	"""

	if not (doctype and name):
		raise Exception('doctype and name required!')

	if not name:
		name = doctype

	if not frappe.db.exists(doctype, name):
		return []

	try:
		doc = frappe.get_doc(doctype, name)
		run_onload(doc)

		if not doc.has_permission("read"):
			frappe.flags.error_message = _('Insufficient Permission for {0}').format(frappe.bold(doctype + ' ' + name))
			raise frappe.PermissionError(("read", doctype, name))

		doc.apply_fieldlevel_read_permissions()

		# add file list
		doc.add_viewed()
		get_docinfo(doc)

	except Exception:
		frappe.errprint(frappe.utils.get_traceback())
		raise

	doc.add_seen()

	frappe.response.docs.append(doc)
```

Ignoring the redundant `if not name: name=doctype` lines for a moment (which are redundant since the previous lines raise an exception unless both doctype and name are supplied), there is a security issue in that `run_onload(doc)` is run *before* the permissions checking. This means onload code, which *may* alter the system in some way (albeit possibly not the best practice) can be run by an unprivileged user.

run_onload should be run only AFTER permissions checking (or you could document that the 'onload' method of every doctype can be run by an unprivileged user...).


Discussion:
This seems like a pretty simple fix... can you send PR? @gbm001 

Resolving patch:
diff --git a/frappe/desk/form/load.py b/frappe/desk/form/load.py
--- a/frappe/desk/form/load.py
+++ b/frappe/desk/form/load.py
@@ -28,14 +28,10 @@ def getdoc(doctype, name, user=None):
 	if not (doctype and name):
 		raise Exception("doctype and name required!")
 
-	if not name:
-		name = doctype
-
 	if not is_virtual_doctype(doctype) and not frappe.db.exists(doctype, name):
 		return []
 
 	doc = frappe.get_doc(doctype, name)
-	run_onload(doc)
 
 	if not doc.has_permission("read"):
 		frappe.flags.error_message = _("Insufficient Permission for {0}").format(
@@ -43,6 +39,8 @@ def getdoc(doctype, name, user=None):
 		)
 		raise frappe.PermissionError(("read", doctype, name))
 
+	
+	run_onload(doc)
 	doc.apply_fieldlevel_read_permissions()
 
 	# add file list


Test patch:
Repository: frappe/frappe

Issue:
Display the datetime in worker.log instead of just time
**Is your feature request related to a problem? Please describe.**
I was trying to understand why I have gotten a certain error and was looking into the logs. I found that the worker.log just displays the time without the date whereas the bench.log and frappe.log displays the datetime as you can see below

![image](https://user-images.githubusercontent.com/11910293/208842264-a196f44a-b932-46af-a398-98eb37c8e0fd.png)

**Describe the solution you'd like**
A clear and concise description of what you want to happen.
I am not sure whether the logging in all parts of the application is standardized? Can we standardize the format across all the log files so that we can see the datetime when an event is logged. 



Discussion:
I am guessing this is just straight from RQ's logging config. 
Ankush,

I am not clear what the next action item is based on your response. Is the
logging config changeable to display the datetime?


Resolving patch:
diff --git a/frappe/utils/background_jobs.py b/frappe/utils/background_jobs.py
--- a/frappe/utils/background_jobs.py
+++ b/frappe/utils/background_jobs.py
@@ -243,7 +243,12 @@ def start_worker(
 		if quiet:
 			logging_level = "WARNING"
 		worker = WorkerKlass(queues, name=get_worker_name(queue_name))
-		worker.work(logging_level=logging_level, burst=burst)
+		worker.work(
+			logging_level=logging_level,
+			burst=burst,
+			date_format="%Y-%m-%d %H:%M:%S",
+			log_format="%(asctime)s,%(msecs)03d %(message)s",
+		)
 
 
 def get_worker_name(queue):


Test patch: