frappe / frappe_docker

Docker images for production and development setups of the Frappe framework and ERPNext
MIT License
1.35k stars 1.28k forks source link

Bench restore failing due to MariaDB Dump File Compatibility Change - /*!999999\- enable the sandbox mode */ #1425

Open me1go opened 2 months ago

me1go commented 2 months ago

Description of the issue

Restoring a backup using the bench command fails because of a MariaDB dump file compatibility change. This issue is related to a new sandbox mode introduced in recent MariaDB versions to improve security, which is not recognized by older MariaDB and MySQL clients.

Context information (for bug reports)

.SQL backup file

-- begin frappe metadata
-- [frappe]
-- version = 15.29.1
-- branch = version-15
-- end frappe metadata
-- 
/*!999999\- enable the sandbox mode */ 
-- MariaDB dump 10.19  Distrib 10.6.18-MariaDB, for debian-linux-gnu (x86_64)
--
-- Host: 127.0.0.1    Database: _86908c96efb9701a

https://mariadb.org/mariadb-dump-file-compatibility-change/

Output of bench version

frappe 15.32.0
frappe@81bf8ea000de:/workspace/development/kf-bench$ bench --version
5.22.6

Steps to reproduce the issue

1.backup erpnext site 2.Restore backup in frappe_docker bench 3.This error is thrown

Observed result

Expected result

Restore from SQL dump should work

Stacktrace / full error message

MySQL root password: 
b"ERROR at line 3: Unknown command '\\-'.\n"
Traceback (most recent call last):
  File "/workspace/development/kf-bench/apps/frappe/frappe/commands/site.py", line 291, in restore_backup
    _new_site(
  File "/workspace/development/kf-bench/apps/frappe/frappe/installer.py", line 87, in _new_site
    install_db(
  File "/workspace/development/kf-bench/apps/frappe/frappe/installer.py", line 160, in install_db
    setup_database(force, source_sql, verbose, no_mariadb_socket)
  File "/workspace/development/kf-bench/apps/frappe/frappe/database/__init__.py", line 21, in setup_database
    return frappe.database.mariadb.setup_db.setup_database(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/development/kf-bench/apps/frappe/frappe/database/mariadb/setup_db.py", line 53, in setup_database
    bootstrap_database(db_name, verbose, source_sql)
  File "/workspace/development/kf-bench/apps/frappe/frappe/database/mariadb/setup_db.py", line 70, in bootstrap_database
    import_db_from_sql(source_sql, verbose)
  File "/workspace/development/kf-bench/apps/frappe/frappe/database/mariadb/setup_db.py", line 93, in import_db_from_sql
    DbManager(frappe.local.db).restore_database(
  File "/workspace/development/kf-bench/apps/frappe/frappe/database/db_manager.py", line 87, in restore_database
    execute_in_shell(" ".join(command), check_exit_code=True, verbose=verbose)
  File "/workspace/development/kf-bench/apps/frappe/frappe/utils/__init__.py", line 484, in execute_in_shell
    raise frappe.CommandFailedError(
frappe.exceptions.CommandFailedError: Command failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/workspace/development/kf-bench/apps/frappe/frappe/utils/bench_helper.py", line 114, in <module>
    main()
  File "/workspace/development/kf-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/workspace/development/kf-bench/env/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/development/kf-bench/env/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/workspace/development/kf-bench/env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/development/kf-bench/env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/development/kf-bench/env/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/development/kf-bench/env/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/development/kf-bench/env/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/development/kf-bench/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/development/kf-bench/apps/frappe/frappe/commands/site.py", line 135, in restore
    _restore(
  File "/workspace/development/kf-bench/apps/frappe/frappe/commands/site.py", line 197, in _restore
    restore_backup(
  File "/workspace/development/kf-bench/apps/frappe/frappe/commands/site.py", line 305, in restore_backup
    print(err.args[1])
          ~~~~~~~~^^^
IndexError: tuple index out of range

Additional information

frappe version 15 using frappe_docker commit c1ee06b6ef10b556bca3078fa5692dabeb8cfe65 (HEAD -> main, origin/main, origin/HEAD)

letajmal commented 1 month ago

You can remove \ from sql file as a work around