diff --git a/.last-branch b/.last-branch index 21015a3..712b150 100644 --- a/.last-branch +++ b/.last-branch @@ -1 +1 @@ -v20260115-09-autotask-customer-company-mapping +v20260115-10-autotask-customers-settings-helper-fix diff --git a/containers/backupchecks/src/backend/app/main/routes_customers.py b/containers/backupchecks/src/backend/app/main/routes_customers.py index 9b01e06..aaf202f 100644 --- a/containers/backupchecks/src/backend/app/main/routes_customers.py +++ b/containers/backupchecks/src/backend/app/main/routes_customers.py @@ -1,12 +1,41 @@ from .routes_shared import * # noqa: F401,F403 +# Explicit imports for robustness across mixed deployments. +from datetime import datetime + +from ..database import db +from ..models import SystemSettings + + +def _get_or_create_settings_local(): + """Return SystemSettings, creating a default row if missing. + + This module should not depend on star-imported helpers for settings. + Mixed deployments (partial container updates) can otherwise raise a + NameError on /customers when the shared helper is not present. + """ + + settings = SystemSettings.query.first() + if settings is None: + settings = SystemSettings( + auto_import_enabled=False, + auto_import_interval_minutes=15, + auto_import_max_items=50, + manual_import_batch_size=50, + auto_import_cutoff_date=datetime.utcnow().date(), + ingest_eml_retention_days=7, + ) + db.session.add(settings) + db.session.commit() + return settings + @main_bp.route("/customers") @login_required @roles_required("admin", "operator", "viewer") def customers(): items = Customer.query.order_by(Customer.name.asc()).all() - settings = _get_or_create_settings() + settings = _get_or_create_settings_local() autotask_enabled = bool(getattr(settings, "autotask_enabled", False)) autotask_configured = bool( (getattr(settings, "autotask_api_username", None)) @@ -51,7 +80,7 @@ def customers(): def _get_autotask_client_or_raise(): """Build an AutotaskClient from settings or raise a user-safe exception.""" - settings = _get_or_create_settings() + settings = _get_or_create_settings_local() if not bool(getattr(settings, "autotask_enabled", False)): raise RuntimeError("Autotask integration is disabled.") if not settings.autotask_api_username or not settings.autotask_api_password or not settings.autotask_tracking_identifier: diff --git a/docs/changelog.md b/docs/changelog.md index 610ef1b..9e4b2d9 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -82,6 +82,14 @@ Changes: - Updated Customers UI to allow searching, selecting, refreshing, and clearing Autotask company mappings. - Ensured mappings remain stable when Autotask company names change and block future ticket actions when mappings are invalid. +## v20260115-10-autotask-customers-settings-helper-fix + +- Fixed /customers crash caused by missing _get_or_create_settings by removing reliance on shared star-imported helpers. +- Added a local SystemSettings get-or-create helper in customers routes to prevent runtime NameError in mixed/partial deployments. +- Added explicit imports for SystemSettings, db, and datetime to keep the Customers page stable across versions. + + + *** ## v0.1.21