diff --git a/frappe/__init__.py b/frappe/__init__.py index 94ad9dad7c..efcbb09503 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -279,13 +279,19 @@ def connect( ) -> None: """Connect to site database instance. - :param site: If site is given, calls `frappe.init`. + :param site: (Deprecated) If site is given, calls `frappe.init`. :param db_name: Optional. Will use from `site_config.json`. :param set_admin_as_user: Set Administrator as current user. """ from frappe.database import get_db if site: + from frappe.utils.deprecations import deprecation_warning + + deprecation_warning( + "Calling frappe.connect with the site argument is deprecated and will be removed in next major version. " + "Instead, explicitly invoke frappe.init(site) prior to calling frappe.connect(), if initializing the site is necessary." + ) init(site) local.db = get_db( diff --git a/frappe/commands/site.py b/frappe/commands/site.py index 73724b8df8..3b6fcb32f1 100644 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -342,7 +342,7 @@ def partial_restore(context, sql_file_path, verbose, encryption_key=None): site = get_site(context) verbose = context.verbose or verbose frappe.init(site=site) - frappe.connect(site=site) + frappe.connect() err, out = frappe.utils.execute_in_shell(f"file {sql_file_path}", check_exit_code=True) if err: click.secho("Failed to detect type of backup file", fg="red") @@ -538,7 +538,8 @@ def add_db_index(context, doctype, column): columns = column # correct naming for site in context.sites: - frappe.connect(site=site) + frappe.init(site=site) + frappe.connect() try: frappe.db.add_index(doctype, columns) if len(columns) == 1: @@ -580,7 +581,8 @@ def describe_database_table(context, doctype, column): import json for site in context.sites: - frappe.connect(site=site) + frappe.init(site=site) + frappe.connect() try: data = _extract_table_stats(doctype, column) # NOTE: Do not print anything else in this to avoid clobbering the output. @@ -666,7 +668,8 @@ def add_system_manager(context, email, first_name, last_name, send_welcome_email import frappe.utils.user for site in context.sites: - frappe.connect(site=site) + frappe.init(site=site) + frappe.connect() try: frappe.utils.user.add_system_manager(email, first_name, last_name, send_welcome_email, password) frappe.db.commit() @@ -692,7 +695,8 @@ def add_user_for_sites( import frappe.utils.user for site in context.sites: - frappe.connect(site=site) + frappe.init(site=site) + frappe.connect() try: add_new_user(email, first_name, last_name, user_type, send_welcome_email, password, add_role) frappe.db.commit() diff --git a/frappe/commands/translate.py b/frappe/commands/translate.py index 5042843405..247d4a77d5 100644 --- a/frappe/commands/translate.py +++ b/frappe/commands/translate.py @@ -34,7 +34,8 @@ def new_language(context, lang_code, app): raise Exception("--site is required") # init site - frappe.connect(site=context["sites"][0]) + frappe.init(site=context["sites"][0]) + frappe.connect() frappe.translate.write_translations_file(app, lang_code) print( diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index d8fcacbbda..5d27fe6e6e 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -108,7 +108,8 @@ def clear_cache(context): for site in context.sites: try: - frappe.connect(site) + frappe.init(site=site) + frappe.connect() frappe.clear_cache() clear_website_cache() finally: diff --git a/frappe/utils/background_jobs.py b/frappe/utils/background_jobs.py index 8029492cde..1283df7e7b 100755 --- a/frappe/utils/background_jobs.py +++ b/frappe/utils/background_jobs.py @@ -188,7 +188,8 @@ def execute_job(site, method, event, job_name, kwargs, user=None, is_async=True, retval = None if is_async: - frappe.connect(site) + frappe.init(site=site) + frappe.connect() if os.environ.get("CI"): frappe.flags.in_test = True