Linking to a Cancelled Document

I’m getting an error that I would like to avoid getting:

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 55, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 21, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 52, in execute_cmd
return, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 907, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/”, line 22, in savedocs
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 230, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 266, in _save
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 400, in _validate
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 640, in _validate_links
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 316, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 306, in msgprint
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 279, in _raise_exception
raise raise_exception, encode(msg)
CancelledLinkError: Cannot link cancelled document: Row #1: Old Document Name: PO-00009

I’d like to avoid getting it because the whole purpose of my document is to link to cancelled documents (this is a controlled document feature I’m working on).

Is there a way to bypass or overwrite the validate links for specific fields? I don’t want to do it for every field (ignore_links).

I’ve tried this:

for doc in self.items:
doc.flags.ignore_links = True

Thanks in advance

If this is not working, a work around could be setting the link field via code (cur_frm.set_query) to pull in all values.

I’m not sure I follow what you mean.

The issue I’m having is on the server side, where once the field has had inputted the cancelled document as a link (which is something I’m able to look up by using the amended_from field), the system checks through to make sure each link is not cancelled. The only way I’ve found to bypass this is by bypassing the checks for the whole document using these functions:

def validate(self):
	self.flags.ignore_links = True

def before_update_after_submit(self):
	self.flags.ignore_links = True

The problem I have with this is that there are certain field I’d like to have checked to make sure they are valid links. Ideally, there would be a checkbox in the setup for each field which indicates whether the link should be validated (with potential for full validation, partial validation of valid doc (cancelled OK), or no validation). I don’t think that exists, but maybe I’m wrong?

I think you are correct, there is no setting/ checkbox on the doctype to achieve this but I was thinking maybe setting the filter through custom JS might help override (but as you say you can see the cancelled values)