shridarpatil / frappe_whatsapp

WhatsApp cloud integration for frappe
https://www.youtube.com/watch?v=nq5Kcc5e1oc
Other
188 stars 169 forks source link

Not able to install after uninstall different version. #104

Closed elbeicktalat closed 1 month ago

elbeicktalat commented 1 month ago

Hi @shridarpatil Thanks for the nice package,

I did uninstall this app some weeks in the past and now I'm facing this issue with installing it again.

The crazy thing is that I'm able to see the Module Def and the other docType.

image

image

Oh by the way if I open any DocType I receive the following message.

image

Also if I open the Module Def I can see it ponting to null.

image

image

Installed Apps

ERPNext: v15.36.1 (version-15)
Frappe Framework: v15.41.0 (version-15)
Frappe HR: v15.29.0 (version-15)
PDF on Submit: v15.1.0 (version-15)
Print Designer: v1.4.2 (main)

Error Log

Installing frappe_whatsapp...
Updating DocTypes for frappe_whatsapp: [=============                           ] 33%An error occurred while installing frappe_whatsapp: Module import failed for WhatsApp Templates, the DocType you're trying to open might be deleted.<br> Error: failed to find libmagic.  Check your installation
Traceback with variables (most recent call last):
  File "apps/frappe/frappe/commands/site.py", line 445, in install_app
    _install_app(app, verbose=context.verbose, force=force)
      context = {'sites': ['site1.local'], 'force': False, 'verbose': False, 'profile': False}
      apps = ('frappe_whatsapp',)
      force = False
      _install_app = <function install_app at 0x7f9f00c01240>
      filelock = <function filelock at 0x7f9f00e0b1c0>
      exit_code = 0
      site = 'site1.local'
      app = 'frappe_whatsapp'
      err = ImportError("Module import failed for WhatsApp Templates, the DocType you're trying to open might be deleted.<br> Error: failed to find libmagic.  Check your installation")
  File "apps/frappe/frappe/installer.py", line 301, in install_app
    sync_for(name, force=force, reset_permissions=True)
      name = 'frappe_whatsapp'
      verbose = False
      set_as_patched = True
      force = False
      sync_jobs = <function sync_jobs at 0x7f9f00113490>
      sync_for = <function sync_for at 0x7f9f00113f40>
      sync_customizations = <function sync_customizations at 0x7f9f019d6dd0>
      sync_fixtures = <function sync_fixtures at 0x7f9f001241f0>
      app_hooks = {'app_description': ['WhatsApp integration for frappe'], 'app_email': ['shridhar.p@zerodha.com'], 'app_include_js': ['/assets/frappe_whatsapp/js/frappe_whatsapp.js'], 'app_license': ['MIT'], 'app_name': ['frappe_whatsapp'], 'app_publisher': ['Shridhar Patil'], 'app_title': ['Frappe Whatsapp'], 'app_version': ['1.0.7'], 'doc_events': {'*': {'before_insert': ['frappe_whatsapp.utils.run_server_script_for_doc_event'], 'after_insert': ['frappe_whatsapp.utils.run_server_script_for_doc_event'], 'before_validate': ['frappe_whatsapp.utils.run_server_script_for_doc_event'], 'validate': ['frappe_whatsapp.utils.run_server_script_for_doc_event'], 'on_update': ['frappe_whatsapp.utils.run_server_script_for_doc_event'], 'before_submit': ['frappe_whatsapp.utils.run_server_script_for_doc_event'], 'on_submit': ['frappe_whatsapp.utils.run_server_script_for_doc_event'], 'before_cancel': ['frappe_whatsapp.utils.run_server_script_for_doc_event'], 'on_cancel': ['frappe_whatsapp.utils.run_server_script_for_doc...
      installed_apps = ['frappe', 'erpnext', 'print_designer', 'pdf_on_submit', 'hrms']
  File "apps/frappe/frappe/model/sync.py", line 111, in sync_for
    import_file_by_path(
      app_name = 'frappe_whatsapp'
      force = False
      reset_permissions = True
      files = ['apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_settings/whatsapp_settings.json', 'apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_message_fields/whatsapp_message_fields.json', 'apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.json', 'apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_message/whatsapp_message.json', 'apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification_log/whatsapp_notification_log.json', 'apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.json']
      module_name = 'frappe_whatsapp'
      folder = 'apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp'
      l = 6
      i = 2
      doc_path = 'apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.json'
  File "apps/frappe/frappe/modules/import_file.py", line 146, in import_file_by_path
    import_doc(
      path = 'apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.json'
      force = False
      data_import = False
      pre_process = None
      ignore_version = True
      reset_permissions = True
      docs = [{'actions': [], 'allow_rename': 1, 'autoname': 'format:{template_name}-{language_code}', 'creation': '2022-10-28 13:39:09.887817', 'doctype': 'DocType', 'editable_grid': 1, 'engine': 'InnoDB', 'fields': [{'fieldname': 'template_name', 'fieldtype': 'Data', 'label': 'Template Label', 'reqd': 1, 'unique': 1, 'doctype': 'DocField'}, {'fieldname': 'actual_name', 'fieldtype': 'Data', 'label': 'Template Name', 'read_only': 1, 'doctype': 'DocField'}, {'fieldname': 'column_break_bthp', 'fieldtype': 'Column Break', 'doctype': 'DocField'}, {'default': 'Pending', 'fieldname': 'status', 'fieldtype': 'Data', 'in_list_view': 1, 'in_standard_filter': 1, 'label': 'Status', 'read_only': 1, 'doctype': 'DocField'}, {'fieldname': 'id', 'fieldtype': 'Data', 'label': 'ID', 'read_only': 1, 'doctype': 'DocField'}, {'fieldname': 'section_break_fxqh', 'fieldtype': 'Section Break', 'doctype': 'DocField'}, {'fieldname': 'template', 'fieldtype': 'Code', 'in_list_view': 1, 'label': 'Template', 'options': 'HTML', 'r...
      calculated_hash = '7eb10c45918cf629458c362aef497aad'
      doc = {'actions': [], 'allow_rename': 1, 'autoname': 'format:{template_name}-{language_code}', 'creation': '2022-10-28 13:39:09.887817', 'doctype': 'DocType', 'editable_grid': 1, 'engine': 'InnoDB', 'fields': [{'fieldname': 'template_name', 'fieldtype': 'Data', 'label': 'Template Label', 'reqd': 1, 'unique': 1, 'doctype': 'DocField'}, {'fieldname': 'actual_name', 'fieldtype': 'Data', 'label': 'Template Name', 'read_only': 1, 'doctype': 'DocField'}, {'fieldname': 'column_break_bthp', 'fieldtype': 'Column Break', 'doctype': 'DocField'}, {'default': 'Pending', 'fieldname': 'status', 'fieldtype': 'Data', 'in_list_view': 1, 'in_standard_filter': 1, 'label': 'Status', 'read_only': 1, 'doctype': 'DocField'}, {'fieldname': 'id', 'fieldtype': 'Data', 'label': 'ID', 'read_only': 1, 'doctype': 'DocField'}, {'fieldname': 'section_break_fxqh', 'fieldtype': 'Section Break', 'doctype': 'DocField'}, {'fieldname': 'template', 'fieldtype': 'Code', 'in_list_view': 1, 'label': 'Template', 'options': 'HTML', 're...
      db_modified_timestamp = None
      is_db_timestamp_latest = None
  File "apps/frappe/frappe/modules/import_file.py", line 239, in import_doc
    doc.insert()
      docdict = {'actions': [], 'allow_rename': 1, 'autoname': 'format:{template_name}-{language_code}', 'creation': '2022-10-28 13:39:09.887817', 'doctype': 'DocType', 'editable_grid': 1, 'engine': 'InnoDB', 'fields': [{'fieldname': 'template_name', 'fieldtype': 'Data', 'label': 'Template Label', 'reqd': 1, 'unique': 1, 'doctype': 'DocField'}, {'fieldname': 'actual_name', 'fieldtype': 'Data', 'label': 'Template Name', 'read_only': 1, 'doctype': 'DocField'}, {'fieldname': 'column_break_bthp', 'fieldtype': 'Column Break', 'doctype': 'DocField'}, {'default': 'Pending', 'fieldname': 'status', 'fieldtype': 'Data', 'in_list_view': 1, 'in_standard_filter': 1, 'label': 'Status', 'read_only': 1, 'doctype': 'DocField'}, {'fieldname': 'id', 'fieldtype': 'Data', 'label': 'ID', 'read_only': 1, 'doctype': 'DocField'}, {'fieldname': 'section_break_fxqh', 'fieldtype': 'Section Break', 'doctype': 'DocField'}, {'fieldname': 'template', 'fieldtype': 'Code', 'in_list_view': 1, 'label': 'Template', 'options': 'HTML', 're...
      data_import = False
      pre_process = None
      ignore_version = True
      reset_permissions = True
      path = 'apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.json'
      controller = <class 'frappe.core.doctype.doctype.doctype.DocType'>
      doc = <DocType: WhatsApp Templates>
  File "apps/frappe/frappe/model/document.py", line 315, in insert
    self.run_post_save_methods()
      self = <DocType: WhatsApp Templates>
      ignore_permissions = None
      ignore_links = None
      ignore_if_duplicate = False
      ignore_mandatory = None
      set_name = None
      set_child_names = True
      d = <DocPerm: abpkq35nja parent=WhatsApp Templates>
  File "apps/frappe/frappe/model/document.py", line 1128, in run_post_save_methods
    self.run_method("on_update")
      self = <DocType: WhatsApp Templates>
  File "apps/frappe/frappe/model/document.py", line 962, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
      self = <DocType: WhatsApp Templates>
      args = ()
      kwargs = {}
      fn = <function Document.run_method.<locals>.fn at 0x7f9efe6da320>
      method = 'on_update'
  File "apps/frappe/frappe/model/document.py", line 1322, in composer
    return composed(self, method, *args, **kwargs)
      self = <DocType: WhatsApp Templates>
      args = ()
      kwargs = {}
      hooks = [<function build_domain_restriced_doctype_cache at 0x7f9f014ff010>, <function clear_doctype_notifications at 0x7f9efe610700>, <function process_workflow_actions at 0x7f9efe613e20>, <function attach_files_to_document at 0x7f9f020abbe0>, <function apply at 0x7f9efe6328c0>, <function update_due_date at 0x7f9efe632950>, <function apply_permissions_for_non_standard_user_type at 0x7f9efe64c1f0>]
      method = 'on_update'
      doc_events = {'*': {'on_update': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions', 'frappe.core.doctype.file.utils.attach_files_to_document', 'frappe.automation.doctype.assignment_rule.assignment_rule.apply', 'frappe.automation.doctype.assignment_rule.assignment_rule.update_due_date', 'frappe.core.doctype.user_type.user_type.apply_permissions_for_non_standard_user_type'], 'after_rename': ['frappe.desk.notifications.clear_doctype_notifications'], 'on_cancel': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions', 'frappe.automation.doctype.assignment_rule.assignment_rule.apply'], 'on_trash': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions'], 'on_update_after_submit': ['frappe.workflow.doctype.workflow_action.workflow_action.process_w...
      handler = 'frappe.core.doctype.user_type.user_type.apply_permissions_for_non_standard_user_type'
      composed = <function Document.hook.<locals>.compose.<locals>.runner at 0x7f9efe6da680>
      compose = <function Document.hook.<locals>.compose at 0x7f9efe6da3b0>
      f = <function Document.run_method.<locals>.fn at 0x7f9efe6da320>
  File "apps/frappe/frappe/model/document.py", line 1304, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
      self = <DocType: WhatsApp Templates>
      method = 'on_update'
      args = ()
      kwargs = {}
      add_to_return_value = <function Document.hook.<locals>.add_to_return_value at 0x7f9efe6da830>
      fn = <function Document.run_method.<locals>.fn at 0x7f9efe6da320>
      hooks = (<function build_domain_restriced_doctype_cache at 0x7f9f014ff010>, <function clear_doctype_notifications at 0x7f9efe610700>, <function process_workflow_actions at 0x7f9efe613e20>, <function attach_files_to_document at 0x7f9f020abbe0>, <function apply at 0x7f9efe6328c0>, <function update_due_date at 0x7f9efe632950>, <function apply_permissions_for_non_standard_user_type at 0x7f9efe64c1f0>)
  File "apps/frappe/frappe/model/document.py", line 959, in fn
    return method_object(*args, **kwargs)
      self = <DocType: WhatsApp Templates>
      args = ()
      kwargs = {}
      method_object = <bound method DocType.on_update of <DocType: WhatsApp Templates>>
      method = 'on_update'
  File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 531, in on_update
    self.run_module_method("on_doctype_update")
      self = <DocType: WhatsApp Templates>
      allow_doctype_export = False
  File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 629, in run_module_method
    module = load_doctype_module(self.name, self.module)
      self = <DocType: WhatsApp Templates>
      method = 'on_doctype_update'
      load_doctype_module = <function load_doctype_module at 0x7f9f019d7370>
  File "apps/frappe/frappe/modules/utils.py", line 258, in load_doctype_module
    raise ImportError(msg) from e
      doctype = 'WhatsApp Templates'
      module = 'Frappe Whatsapp'
      prefix = ''
      suffix = ''
      app = 'frappe_whatsapp'
      key = ********
      module_name = 'frappe_whatsapp.frappe_whatsapp.doctype.whatsapp_templates.whatsapp_templates'
      msg = "Module import failed for WhatsApp Templates, the DocType you're trying to open might be deleted.<br> Error: failed to find libmagic.  Check your installation"
builtins.ImportError: Module import failed for WhatsApp Templates, the DocType you're trying to open might be deleted.<br> Error: failed to find libmagic.  Check your installation
elbeicktalat commented 1 month ago

Ah if I try to run install another time I get:

frappe.exceptions.DuplicateEntryError: ('Module Def', 'Frappe Whatsapp', IntegrityError(1062, "Duplicate entry 'Frappe Whatsapp' for key 'PRIMARY'"))
chechani commented 1 month ago

run

bench setup requirements
bench restart
bench --site {site_name} migrate --force
elbeicktalat commented 1 month ago

@chechani Thank you.

I have done the migration, you can see the log, but still not able to see the app.

bench --site site1.local migrate
Migrating site1.local
Updating DocTypes for frappe        : [========================================] 100%
Updating DocTypes for erpnext       : [========================================] 100%
Updating DocTypes for print_designer: [========================================] 100%
Updating DocTypes for pdf_on_submit : [========================================] 100%
Updating DocTypes for hrms          : [========================================] 100%
Updating Dashboard for frappe
Updating Dashboard for erpnext
Updating Dashboard for print_designer
Updating Dashboard for pdf_on_submit
Updating Dashboard for hrms
Updating customizations for Address
Updating customizations for Contact
Orphaned DocType(s) found: WhatsApp Templates
Deleting orphaned DocTypes          : [========================================] 100%
Queued rebuilding of search index for site1.local

Any Idea?

elbeicktalat commented 1 month ago

@chechani

bench setup requirements //done bench restart //done bench --site {site_name} migrate --force // done without --force

--force not available

chechani commented 1 month ago

Sorry, I meant bench - - site (site_name) install-app frappe_whatsapp - - force and then run migrate

shridarpatil commented 1 month ago

This is because the app was not uninstalled properly. Delete all the entries from module def for WhatsApp. Delete this directly from db. And then install the app again. Also make sure to pull the latest changes before reinstalling

elbeicktalat commented 1 month ago

I think you mean to delete the DocType related to Frappe Whatsapp and what about Module Def?

DELETE FROM `tabDocType` WHERE module = "Frappe Whatsapp";

I noted if I run bench uninstall-app frappe_whatsapp --force it removes theam as well as the Frappe Whatsapp Module Def.

What to do?

elbeicktalat commented 1 month ago

@chechani I tried following commands as you said:

bench setup requirements
bench restart
bench -- site (site_name) install-app frappe_whatsapp -- force
bench --site {site_name} migrate

This didn't solve, note I tried after removing the app with --force and also before removing it.

elbeicktalat commented 1 month ago

@shridarpatil Thanks for your time,

I tried what you suggested:

  1. Removed all docType relate to Frappe WhatsApp
  2. Removed the Frappe WhatsApp Module Def
  3. Pull app changes with bench get-app https://github.com/shridarpatil/frappe_whatsapp
  4. Install the app again with and without --force

There is something related to WhatsApp Templates DocType and a dependency failed to find libmagic

What do you suggest?

elbeicktalat commented 1 month ago

@chechani @shridarpatil Any Idea?

elbeicktalat commented 1 month ago

:tada: Finally I have solved the issue.

bench uninstall-app frappe_whatsapp --force
bench remove-app frappe_whatsapp
bench get-app https://github.com/shridarpatil/frappe_whatsapp --resolve-deps
bench setup requirements
bench restart
bench --site [sitename] install-app frappe_whatsapp --force
bench --site {site_name} migrate

Probably it will solve with adding --resolve-deps to the bench get-app command.