diff --git a/app/models/tenant_settings.py b/app/models/tenant_settings.py index 4bcb4bb..2ffe627 100644 --- a/app/models/tenant_settings.py +++ b/app/models/tenant_settings.py @@ -35,8 +35,19 @@ class TenantSettings(db.Model): @classmethod def get_or_default(cls): - """Return the settings row, or a default-filled instance (not persisted).""" - row = cls.query.first() + """Return the settings row, a default-filled transient instance, or None. + + Returns None when the tenant_settings table does not yet exist (i.e. + phase33 migration has not been run for this tenant DB). The caller + must handle None — routes redirect to the dashboard with a migration + prompt; the context processor silently returns no branding. + """ + try: + row = cls.query.first() + except Exception: + # ProgrammingError: Table 'tenant_settings' doesn't exist + # (phase33 migration not yet applied to this tenant DB) + return None if row is not None: return row # Return a transient default so templates always get a real object.