Common Ignore Options in doc events

In Frappe, ignore options are flags or properties used to bypass certain checks or default behaviors during document operations. These options are particularly useful when you need to perform actions that would otherwise be restricted by the framework's built-in validations or workflows.

Common Ignore Options

  1. ignore_permissions

    • Bypasses user permission checks for the operation.
    • Useful for background processes or admin-level scripts.
    • Example:
      doc = frappe.get_doc("DocType", docname)
      doc.flags.ignore_permissions = True
      doc.save()
      
  2. ignore_mandatory

    • Skips mandatory field validation.
    • Allows saving or submitting documents even if mandatory fields are empty.
    • Example:
      doc = frappe.new_doc("DocType")
      doc.flags.ignore_mandatory = True
      doc.save()
      
  3. ignore_validate

    • Skips custom validation logic defined in validate hooks or methods.
    • Useful for bypassing validations during imports or data corrections.
    • Example:
      doc = frappe.get_doc("DocType", docname)
      doc.flags.ignore_validate = True
      doc.save()
      
  4. ignore_links

    • Ignores checks for linked documents when deleting or modifying a document.
    • Useful when cleaning up data or fixing inconsistencies.
    • Example:
      frappe.delete_doc("DocType", docname, ignore_links=True)
      
  5. ignore_save_passwords

    • Prevents saving or encrypting password-type fields in the __Auth table.
    • Example:
      doc = frappe.get_doc("User", "user@example.com")
      doc.flags.ignore_save_passwords = True
      doc.save()
      
  6. ignore_children

    • Skips processing or saving child table data when saving a document.
    • Useful for operations focused only on the parent document.
    • Example:
      doc = frappe.get_doc("DocType", docname)
      doc.flags.ignore_children = True
      doc.save()
      
  7. ignore_version

    • Disables versioning for the document during the current operation.
    • Example:
      doc = frappe.get_doc("DocType", docname)
      doc.flags.ignore_version = True
      doc.save()
      
  8. ignore_if_duplicate

    • Avoids errors when trying to insert a duplicate primary key.
    • Mostly used during database operations.
    • Example:
      doc.db_insert(ignore_if_duplicate=True)
      
  9. ignore_validate_update_after_submit

    • Bypasses the validation that restricts updating a document after submission.
    • Example:
      doc = frappe.get_doc("DocType", docname)
      doc.flags.ignore_validate_update_after_submit = True
      doc.save()
      
  10. ignore_cancelation

    • Prevents the document's cancellation logic from being executed.
    • Example:
      doc = frappe.get_doc("DocType", docname)
      doc.flags.ignore_cancelation = True
      doc.cancel()
      
  11. ignore_docstatus

    • Allows modifications to documents with specific docstatus values.
    • Example:
      doc = frappe.get_doc("DocType", docname)
      doc.flags.ignore_docstatus = True
      doc.save()
      
  12. ignore_validate_constants

    • Skips the validation for fields marked as Set Only Once.
    • Example:
      doc = frappe.get_doc("DocType", docname)
      doc.flags.ignore_validate_constants = True
      doc.save()
      
  13. ignore_field_comparison

    • Disables comparison checks between current and previous values during updates.
    • Example:
      doc = frappe.get_doc("DocType", docname)
      doc.flags.ignore_field_comparison = True
      doc.save()
      

When to Use Ignore Options

  • Data Imports: Avoid strict validations for bulk data operations.
  • Scripting/Automation: Customize behavior in background processes or scripts.
  • Data Correction: Bypass restrictions to fix inconsistencies.

Caution

Using ignore options can potentially lead to: - Inconsistent data. - Bypassing critical business rules. - Violations of data integrity.

These flags should only be used with a full understanding of their implications.

Discard
Save
Was this article helpful?

On this page