Jun 28 Optimize code - fix new tenant settings error
This commit is contained in:
@@ -35,8 +35,19 @@ class TenantSettings(db.Model):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_or_default(cls):
|
def get_or_default(cls):
|
||||||
"""Return the settings row, or a default-filled instance (not persisted)."""
|
"""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()
|
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:
|
if row is not None:
|
||||||
return row
|
return row
|
||||||
# Return a transient default so templates always get a real object.
|
# Return a transient default so templates always get a real object.
|
||||||
|
|||||||
Reference in New Issue
Block a user