Auto-commit local changes before build (2026-01-15 14:14:29)

This commit is contained in:
Ivo Oskamp 2026-01-15 14:14:29 +01:00
parent c68b401709
commit 186807b098
3 changed files with 40 additions and 3 deletions

View File

@ -1 +1 @@
v20260115-09-autotask-customer-company-mapping v20260115-10-autotask-customers-settings-helper-fix

View File

@ -1,12 +1,41 @@
from .routes_shared import * # noqa: F401,F403 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") @main_bp.route("/customers")
@login_required @login_required
@roles_required("admin", "operator", "viewer") @roles_required("admin", "operator", "viewer")
def customers(): def customers():
items = Customer.query.order_by(Customer.name.asc()).all() 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_enabled = bool(getattr(settings, "autotask_enabled", False))
autotask_configured = bool( autotask_configured = bool(
(getattr(settings, "autotask_api_username", None)) (getattr(settings, "autotask_api_username", None))
@ -51,7 +80,7 @@ def customers():
def _get_autotask_client_or_raise(): def _get_autotask_client_or_raise():
"""Build an AutotaskClient from settings or raise a user-safe exception.""" """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)): if not bool(getattr(settings, "autotask_enabled", False)):
raise RuntimeError("Autotask integration is disabled.") raise RuntimeError("Autotask integration is disabled.")
if not settings.autotask_api_username or not settings.autotask_api_password or not settings.autotask_tracking_identifier: if not settings.autotask_api_username or not settings.autotask_api_password or not settings.autotask_tracking_identifier:

View File

@ -82,6 +82,14 @@ Changes:
- Updated Customers UI to allow searching, selecting, refreshing, and clearing Autotask company mappings. - 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. - 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 ## v0.1.21