ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
refactor(models): finish JsonColumnMixin adoption — no hand-rolled json.loads (plan 77 B4)
Juan Denise810016005f2
diff --git a/backend/app/models/agent_plugin.py b/backend/app/models/agent_plugin.pyindex 3b99b8a7..162407f7 100644--- a/backend/app/models/agent_plugin.py+++ b/backend/app/models/agent_plugin.py@@ -1,10 +1,11 @@from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import TimestampMixinimport json-class AgentPlugin(TimestampMixin, db.Model):+class AgentPlugin(JsonColumnMixin, TimestampMixin, db.Model):"""Represents a plugin that can be installed on agents."""__tablename__ = 'agent_plugins'@@ -43,7 +44,7 @@ class AgentPlugin(TimestampMixin, db.Model):@propertydef manifest(self):- return json.loads(self.manifest_json) if self.manifest_json else {}+ return self._json_read('manifest_json')@manifest.setterdef manifest(self, value):@@ -51,7 +52,7 @@ class AgentPlugin(TimestampMixin, db.Model):@propertydef capabilities(self):- return json.loads(self.capabilities_json) if self.capabilities_json else []+ return self._json_read('capabilities_json', [])@capabilities.setterdef capabilities(self, value):@@ -59,7 +60,7 @@ class AgentPlugin(TimestampMixin, db.Model):@propertydef dependencies(self):- return json.loads(self.dependencies_json) if self.dependencies_json else []+ return self._json_read('dependencies_json', [])@dependencies.setterdef dependencies(self, value):@@ -67,7 +68,7 @@ class AgentPlugin(TimestampMixin, db.Model):@propertydef permissions(self):- return json.loads(self.permissions_json) if self.permissions_json else []+ return self._json_read('permissions_json', [])@permissions.setterdef permissions(self, value):@@ -98,7 +99,7 @@ class AgentPlugin(TimestampMixin, db.Model):return f'<AgentPlugin {self.name}@{self.version}>'-class AgentPluginInstall(db.Model):+class AgentPluginInstall(JsonColumnMixin, db.Model):"""Tracks plugin installations on specific agents/servers."""__tablename__ = 'agent_plugin_installs'@@ -130,7 +131,7 @@ class AgentPluginInstall(db.Model):@propertydef config(self):- return json.loads(self.config_json) if self.config_json else {}+ return self._json_read('config_json')@config.setterdef config(self, value):@@ -138,7 +139,7 @@ class AgentPluginInstall(db.Model):@propertydef metrics(self):- return json.loads(self.metrics_json) if self.metrics_json else {}+ return self._json_read('metrics_json')def to_dict(self):return {diff --git a/backend/app/models/ai.py b/backend/app/models/ai.pyindex 22bca4e0..9280f38d 100644--- a/backend/app/models/ai.py+++ b/backend/app/models/ai.py@@ -19,6 +19,7 @@ import uuidfrom datetime import datetime, timedeltafrom app import db+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import TimestampMixin@@ -27,7 +28,7 @@ def _new_id() -> str:return uuid.uuid4().hex-class AiConversation(TimestampMixin, db.Model):+class AiConversation(JsonColumnMixin, TimestampMixin, db.Model):"""A single AI chat thread owned by a user."""__tablename__ = 'ai_conversations'@@ -52,7 +53,7 @@ class AiConversation(TimestampMixin, db.Model):@propertydef export(self) -> dict:- return json.loads(self.export_json) if self.export_json else {}+ return self._json_read('export_json')@export.setterdef export(self, value) -> None:@@ -75,7 +76,7 @@ class AiConversation(TimestampMixin, db.Model):return data-class AiMessage(db.Model):+class AiMessage(JsonColumnMixin, db.Model):"""One persisted turn in a conversation (user, assistant, or tool)."""__tablename__ = 'ai_messages'@@ -95,7 +96,7 @@ class AiMessage(db.Model):@propertydef tool_calls(self) -> list:- return json.loads(self.tool_calls_json) if self.tool_calls_json else []+ return self._json_read('tool_calls_json', [])@tool_calls.setterdef tool_calls(self, value) -> None:@@ -103,7 +104,7 @@ class AiMessage(db.Model):@propertydef usage(self) -> dict:- return json.loads(self.usage_json) if self.usage_json else {}+ return self._json_read('usage_json')@usage.setterdef usage(self, value) -> None:@@ -121,7 +122,7 @@ class AiMessage(db.Model):}-class AiPendingAction(db.Model):+class AiPendingAction(JsonColumnMixin, db.Model):"""A guarded write-tool action awaiting human confirmation.Live approve/deny is coordinated in-memory by the streaming worker; this@@ -154,7 +155,7 @@ class AiPendingAction(db.Model):@propertydef params(self) -> dict:- return json.loads(self.params_json) if self.params_json else {}+ return self._json_read('params_json')@params.setterdef params(self, value) -> None:@@ -162,7 +163,7 @@ class AiPendingAction(db.Model):@propertydef result(self):- return json.loads(self.result_json) if self.result_json else None+ return self._json_read('result_json', None)@result.setterdef result(self, value) -> None:diff --git a/backend/app/models/application.py b/backend/app/models/application.pyindex 1755f358..fd174828 100644--- a/backend/app/models/application.py+++ b/backend/app/models/application.py@@ -7,6 +7,7 @@ from app import db# FK targets resolvable regardless of import order.from app.models import project as _project # noqa: F401from app.models import environment as _environment # noqa: F401+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import SoftDeleteMixin, TimestampMixinfrom app.utils.ingress import (default_ingress_plane as _default_ingress_plane,@@ -14,7 +15,7 @@ from app.utils.ingress import ()-class Application(TimestampMixin, SoftDeleteMixin, db.Model):+class Application(JsonColumnMixin, TimestampMixin, SoftDeleteMixin, db.Model):"""A managed app.SOFT DELETED (plan 70). `Application.query` therefore returns TOMBSTONES —@@ -200,7 +201,6 @@ class Application(TimestampMixin, SoftDeleteMixin, db.Model):`fields=None` keeps the full legacy payload, so every existing calleris unaffected."""- import jsonwant = fields.__contains__ if fields is not None else (lambda _key: True)result = {'id': self.id,@@ -218,8 +218,8 @@ class Application(TimestampMixin, SoftDeleteMixin, db.Model):'cpu_limit': self.cpu_limit,'memory_limit': self.memory_limit,'buildpack_type': self.buildpack_type,- 'buildpack_plan': json.loads(self.buildpack_plan) if self.buildpack_plan else None,- 'buildpack_overrides': json.loads(self.buildpack_overrides) if self.buildpack_overrides else None,+ 'buildpack_plan': self._json_read('buildpack_plan', None),+ 'buildpack_overrides': self._json_read('buildpack_overrides', None),'source': self.source,'compose_file': self.compose_file,'systemd_unit': self.systemd_unit,@@ -231,7 +231,7 @@ class Application(TimestampMixin, SoftDeleteMixin, db.Model):'micro_cache_enabled': bool(self.micro_cache_enabled),'environment_type': self.environment_type,'linked_app_id': self.linked_app_id,- 'shared_config': json.loads(self.shared_config) if self.shared_config else None,+ 'shared_config': self._json_read('shared_config', None),'created_at': self.created_at.isoformat(),'updated_at': self.updated_at.isoformat(),'last_deployed_at': self.last_deployed_at.isoformat() if self.last_deployed_at else None,diff --git a/backend/app/models/cloud_server.py b/backend/app/models/cloud_server.pyindex a033d7ac..d8a0d028 100644--- a/backend/app/models/cloud_server.py+++ b/backend/app/models/cloud_server.py@@ -1,5 +1,6 @@from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinimport json@@ -28,7 +29,7 @@ class CloudProvider(db.Model):}-class CloudServer(db.Model):+class CloudServer(JsonColumnMixin, db.Model):"""A cloud server provisioned through ServerKit."""__tablename__ = 'cloud_servers'@@ -74,7 +75,7 @@ class CloudServer(db.Model):@propertydef server_metadata(self):- return json.loads(self.metadata_json) if self.metadata_json else {}+ return self._json_read('metadata_json')@server_metadata.setterdef server_metadata(self, v):diff --git a/backend/app/models/db_snapshot.py b/backend/app/models/db_snapshot.pyindex f8027688..44923fbb 100644--- a/backend/app/models/db_snapshot.py+++ b/backend/app/models/db_snapshot.py@@ -15,11 +15,11 @@ stable core-managed schema seam, not a reason to keep them in the WP file.from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import TimestampMixin-import json-class DatabaseSnapshot(db.Model):+class DatabaseSnapshot(JsonColumnMixin, db.Model):"""Point-in-time database snapshots for WordPress sites."""__tablename__ = 'database_snapshots'@@ -66,7 +66,7 @@ class DatabaseSnapshot(db.Model):'compressed': self.compressed,'commit_sha': self.commit_sha,'commit_message': self.commit_message,- 'tables_included': json.loads(self.tables_included) if self.tables_included else None,+ 'tables_included': self._json_read('tables_included', None),'row_count': self.row_count,'status': self.status,'error_message': self.error_message,@@ -88,7 +88,7 @@ class DatabaseSnapshot(db.Model):return f'<DatabaseSnapshot {self.id} "{self.name}">'-class SyncJob(TimestampMixin, db.Model):+class SyncJob(JsonColumnMixin, TimestampMixin, db.Model):"""Scheduled database synchronization jobs between WordPress environments."""__tablename__ = 'sync_jobs'@@ -127,7 +127,7 @@ class SyncJob(TimestampMixin, db.Model):'target_site_id': self.target_site_id,'schedule': self.schedule,'enabled': self.enabled,- 'config': json.loads(self.config) if self.config else None,+ 'config': self._json_read('config', None),'last_run': self.last_run.isoformat() if self.last_run else None,'last_run_status': self.last_run_status,'last_run_duration': self.last_run_duration,diff --git a/backend/app/models/deployment.py b/backend/app/models/deployment.pyindex 900217a2..b0f55349 100644--- a/backend/app/models/deployment.py+++ b/backend/app/models/deployment.py@@ -172,7 +172,7 @@ class Deployment(JsonColumnMixin, db.Model):return f'<Deployment app={self.app_id} v{self.version} status={self.status}>'-class DeploymentDiff(db.Model):+class DeploymentDiff(JsonColumnMixin, db.Model):"""Stores diff information between deployments."""__tablename__ = 'deployment_diffs'@@ -198,9 +198,9 @@ class DeploymentDiff(db.Model):'id': self.id,'deployment_id': self.deployment_id,'previous_deployment_id': self.previous_deployment_id,- 'files_added': json.loads(self.files_added) if self.files_added else [],- 'files_removed': json.loads(self.files_removed) if self.files_removed else [],- 'files_modified': json.loads(self.files_modified) if self.files_modified else [],+ 'files_added': self._json_read('files_added', []),+ 'files_removed': self._json_read('files_removed', []),+ 'files_modified': self._json_read('files_modified', []),'additions': self.additions,'deletions': self.deletions,'created_at': self.created_at.isoformat() if self.created_at else Nonediff --git a/backend/app/models/deployment_job.py b/backend/app/models/deployment_job.pyindex 4ebd9f72..a62b90d5 100644--- a/backend/app/models/deployment_job.py+++ b/backend/app/models/deployment_job.py@@ -7,9 +7,10 @@ from datetime import datetimeimport jsonfrom app import db+from app.models.json_column_mixin import JsonColumnMixin-class DeploymentJob(db.Model):+class DeploymentJob(JsonColumnMixin, db.Model):"""A runnable deployment job with status, target, plan, and result."""__tablename__ = 'deployment_jobs'@@ -65,10 +66,7 @@ class DeploymentJob(db.Model):)def get_plan(self):- try:- return json.loads(self.plan) if self.plan else {}- except (TypeError, json.JSONDecodeError):- return {}+ return self._json_read('plan')def set_plan(self, plan):self.plan = json.dumps(plan)@@ -76,10 +74,7 @@ class DeploymentJob(db.Model):self.total_steps = len(steps)def get_result(self):- try:- return json.loads(self.result) if self.result else {}- except (TypeError, json.JSONDecodeError):- return {}+ return self._json_read('result')def set_result(self, result):self.result = json.dumps(result or {})@@ -137,7 +132,7 @@ class DeploymentJob(db.Model):return data-class DeploymentJobLog(db.Model):+class DeploymentJobLog(JsonColumnMixin, db.Model):"""A timestamped deployment job log entry."""__tablename__ = 'deployment_job_logs'@@ -160,10 +155,7 @@ class DeploymentJobLog(db.Model):job = db.relationship('DeploymentJob', back_populates='logs')def get_data(self):- try:- return json.loads(self.data) if self.data else None- except (TypeError, json.JSONDecodeError):- return None+ return self._json_read('data', None)def to_dict(self):return {diff --git a/backend/app/models/dns_zone.py b/backend/app/models/dns_zone.pyindex 098aa5db..8801e5b1 100644--- a/backend/app/models/dns_zone.py+++ b/backend/app/models/dns_zone.py@@ -1,10 +1,11 @@from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import TimestampMixinimport json-class DNSZone(TimestampMixin, db.Model):+class DNSZone(JsonColumnMixin, TimestampMixin, db.Model):"""DNS zone for a domain with provider integration."""__tablename__ = 'dns_zones'@@ -28,7 +29,7 @@ class DNSZone(TimestampMixin, db.Model):@propertydef provider_config(self):- return json.loads(self.provider_config_json) if self.provider_config_json else {}+ return self._json_read('provider_config_json')@provider_config.setterdef provider_config(self, v):diff --git a/backend/app/models/environment_activity.py b/backend/app/models/environment_activity.pyindex c78437fb..beee2e47 100644--- a/backend/app/models/environment_activity.py+++ b/backend/app/models/environment_activity.py@@ -7,10 +7,10 @@ Tracks who did what, when, and how long it took.from datetime import datetimefrom app import db-import json+from app.models.json_column_mixin import JsonColumnMixin-class EnvironmentActivity(db.Model):+class EnvironmentActivity(JsonColumnMixin, db.Model):"""Audit log for environment actions."""__tablename__ = 'environment_activities'@@ -43,7 +43,7 @@ class EnvironmentActivity(db.Model):'user_id': self.user_id,'action': self.action,'description': self.description,- 'metadata': json.loads(self.activity_metadata) if self.activity_metadata else None,+ 'metadata': self._json_read('activity_metadata', None),'status': self.status,'error_message': self.error_message,'duration_seconds': self.duration_seconds,diff --git a/backend/app/models/host_snapshot.py b/backend/app/models/host_snapshot.pyindex 6cfe3d29..9a15d542 100644--- a/backend/app/models/host_snapshot.py+++ b/backend/app/models/host_snapshot.py@@ -13,9 +13,10 @@ import jsonfrom datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixin-class HostSnapshot(db.Model):+class HostSnapshot(JsonColumnMixin, db.Model):"""One reading of the panel host's specs and filesystems."""__tablename__ = 'host_snapshots'@@ -45,16 +46,8 @@ class HostSnapshot(db.Model):# a state transition instead of nagging every boot.advisories_json = db.Column(db.Text, nullable=True)- def _load(self, raw, default):- if not raw:- return default- try:- return json.loads(raw)- except (json.JSONDecodeError, TypeError):- return default-def get_filesystems(self):- return self._load(self.filesystems_json, [])+ return self._json_read('filesystems_json', [])def set_filesystems(self, value):self.filesystems_json = json.dumps(value) if value else None@@ -63,13 +56,13 @@ class HostSnapshot(db.Model):"""Deltas vs the previous snapshot, or None if this is the first."""if self.changes_json is None:return None- return self._load(self.changes_json, [])+ return self._json_read('changes_json', [])def set_changes(self, value):self.changes_json = json.dumps(value) if value is not None else Nonedef get_advisories(self):- return self._load(self.advisories_json, [])+ return self._json_read('advisories_json', [])def set_advisories(self, value):self.advisories_json = json.dumps(value) if value else Nonediff --git a/backend/app/models/image_scan.py b/backend/app/models/image_scan.pyindex 6cb1a258..944dc97f 100644--- a/backend/app/models/image_scan.py+++ b/backend/app/models/image_scan.py@@ -59,7 +59,7 @@ class ImageVulnerabilityScan(JsonColumnMixin, db.Model):}-class SbomArtifact(db.Model):+class SbomArtifact(JsonColumnMixin, db.Model):"""Generated SPDX SBOM for a Docker image."""__tablename__ = 'sbom_artifacts'@@ -83,5 +83,5 @@ class SbomArtifact(db.Model):'generator_version': self.generator_version,'format': self.format,'created_at': self.created_at.isoformat() if self.created_at else None,- 'sbom': json.loads(self.sbom_json) if include_sbom and self.sbom_json else None,+ 'sbom': self._json_read('sbom_json', None) if include_sbom else None,}diff --git a/backend/app/models/json_column_mixin.py b/backend/app/models/json_column_mixin.pyindex b0677ddc..c14f63d8 100644--- a/backend/app/models/json_column_mixin.py+++ b/backend/app/models/json_column_mixin.py@@ -25,9 +25,12 @@ optional shape check, falsy-on-write.Corrupt JSON reads as the default, never raises: a hand-edited orpartially-written row must not 500 every endpoint that serializes the model.-This is the dominant in-tree convention; the handful of models that let-``json.loads`` raise on corrupt data are deliberately NOT converted (that-would be a behaviour change, not a consolidation).+This is the tree-wide convention as of plan 77 B4, which reversed the earlier+ruling that unprotected ``json.loads`` sites were out of scope: the sites that+used to let corrupt data raise were converted too, so a corrupt row now+degrades to the accessor's default instead of failing every request that+touches it. No model file hand-rolls ``json.loads`` any more (ratcheted by+``tests/test_models_json_one_door.py``)."""import jsondiff --git a/backend/app/models/plugin.py b/backend/app/models/plugin.pyindex c1178dbe..8c0023c1 100644--- a/backend/app/models/plugin.py+++ b/backend/app/models/plugin.py@@ -1,10 +1,11 @@"""Installed plugin tracking model."""from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinimport json-class InstalledPlugin(db.Model):+class InstalledPlugin(JsonColumnMixin, db.Model):"""Tracks plugins installed from external sources (zips/URLs)."""__tablename__ = 'installed_plugins'@@ -63,7 +64,7 @@ class InstalledPlugin(db.Model):@propertydef manifest(self):- return json.loads(self.manifest_json) if self.manifest_json else {}+ return self._json_read('manifest_json')@manifest.setterdef manifest(self, v):@@ -71,7 +72,7 @@ class InstalledPlugin(db.Model):@propertydef config(self):- return json.loads(self.config_json) if self.config_json else {}+ return self._json_read('config_json')@config.setterdef config(self, v):diff --git a/backend/app/models/project.py b/backend/app/models/project.pyindex ac0414e5..d9de64ed 100644--- a/backend/app/models/project.py+++ b/backend/app/models/project.py@@ -1,10 +1,11 @@from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import TimestampMixinimport json-class Project(TimestampMixin, db.Model):+class Project(JsonColumnMixin, TimestampMixin, db.Model):"""A Project groups applications under a Workspace.Hierarchy: Workspace -> Project -> Environment -> Applications.@@ -38,7 +39,7 @@ class Project(TimestampMixin, db.Model):@propertydef metadata_(self):- return json.loads(self.metadata_json) if self.metadata_json else {}+ return self._json_read('metadata_json')@metadata_.setterdef metadata_(self, v):diff --git a/backend/app/models/promotion_job.py b/backend/app/models/promotion_job.pyindex 160d2fdb..84f4e8d9 100644--- a/backend/app/models/promotion_job.py+++ b/backend/app/models/promotion_job.py@@ -7,10 +7,10 @@ Tracks code/data promotions between WordPress environmentsfrom datetime import datetimefrom app import db-import json+from app.models.json_column_mixin import JsonColumnMixin-class PromotionJob(db.Model):+class PromotionJob(JsonColumnMixin, db.Model):"""Track code/data promotions between environments."""__tablename__ = 'promotion_jobs'@@ -54,7 +54,7 @@ class PromotionJob(db.Model):'target_site_id': self.target_site_id,'user_id': self.user_id,'promotion_type': self.promotion_type,- 'config': json.loads(self.config) if self.config else None,+ 'config': self._json_read('config', None),'status': self.status,'pre_promotion_snapshot_id': self.pre_promotion_snapshot_id,'error_message': self.error_message,diff --git a/backend/app/models/registrar_connection.py b/backend/app/models/registrar_connection.pyindex acedd85f..0a98b6bf 100644--- a/backend/app/models/registrar_connection.py+++ b/backend/app/models/registrar_connection.py@@ -1,9 +1,10 @@from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import EncryptedSecret, TimestampMixin-class RegistrarConnection(TimestampMixin, db.Model):+class RegistrarConnection(JsonColumnMixin, TimestampMixin, db.Model):"""A connected domain-registrar account (GoDaddy, …) used to read the domainportfolio: registration status, expiry dates, auto-renew and nameservers.@@ -27,13 +28,7 @@ class RegistrarConnection(TimestampMixin, db.Model):@propertydef config(self):- import json- if not self.config_json:- return {}- try:- return json.loads(self.config_json)- except Exception:- return {}+ return self._json_read('config_json')@config.setterdef config(self, value):diff --git a/backend/app/models/server_onboarding_log.py b/backend/app/models/server_onboarding_log.pyindex 9570fe29..5f8ef670 100644--- a/backend/app/models/server_onboarding_log.py+++ b/backend/app/models/server_onboarding_log.py@@ -12,9 +12,10 @@ import jsonfrom datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixin-class ServerOnboardingLog(db.Model):+class ServerOnboardingLog(JsonColumnMixin, db.Model):__tablename__ = 'server_onboarding_logs'STATUS_STARTED = 'started'@@ -34,10 +35,7 @@ class ServerOnboardingLog(db.Model):created_at = db.Column(db.DateTime, default=datetime.utcnow, index=True)def get_detail(self):- try:- return json.loads(self.detail_json) if self.detail_json else {}- except (TypeError, json.JSONDecodeError):- return {}+ return self._json_read('detail_json')def set_detail(self, detail):self.detail_json = json.dumps(detail or {})diff --git a/backend/app/models/server_survey.py b/backend/app/models/server_survey.pyindex a96f754e..c569bbc1 100644--- a/backend/app/models/server_survey.py+++ b/backend/app/models/server_survey.py@@ -2,9 +2,10 @@ import jsonfrom datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixin-class ServerSurvey(db.Model):+class ServerSurvey(JsonColumnMixin, db.Model):"""One read-only survey snapshot ("flight") of a paired server (plan 27,Decision 3: snapshots, not live state).@@ -32,12 +33,7 @@ class ServerSurvey(db.Model):map_json = db.Column(db.Text, nullable=True)def get_map(self):- if not self.map_json:- return {}- try:- return json.loads(self.map_json)- except (json.JSONDecodeError, TypeError):- return {}+ return self._json_read('map_json')def set_map(self, value):self.map_json = json.dumps(value) if value else Nonediff --git a/backend/app/models/server_template.py b/backend/app/models/server_template.pyindex 89039c26..a3031c20 100644--- a/backend/app/models/server_template.py+++ b/backend/app/models/server_template.py@@ -1,10 +1,11 @@from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import TimestampMixinimport json-class ServerTemplate(TimestampMixin, db.Model):+class ServerTemplate(JsonColumnMixin, TimestampMixin, db.Model):"""Defines expected state for a server — packages, services, firewall rules, users, files."""__tablename__ = 'server_templates'@@ -37,8 +38,7 @@ class ServerTemplate(TimestampMixin, db.Model):assignments = db.relationship('ServerTemplateAssignment', backref='template', lazy='dynamic')def _get_json(self, field):- val = getattr(self, field)- return json.loads(val) if val else []+ return self._json_read(field, [])def _set_json(self, field, value):setattr(self, field, json.dumps(value))@@ -148,7 +148,7 @@ class ServerTemplate(TimestampMixin, db.Model):return f'<ServerTemplate {self.name} v{self.version}>'-class ServerTemplateAssignment(db.Model):+class ServerTemplateAssignment(JsonColumnMixin, db.Model):"""Tracks which template is applied to which server."""__tablename__ = 'server_template_assignments'@@ -180,7 +180,7 @@ class ServerTemplateAssignment(db.Model):@propertydef drift_report(self):- return json.loads(self.drift_report_json) if self.drift_report_json else {}+ return self._json_read('drift_report_json')@drift_report.setterdef drift_report(self, v):diff --git a/backend/app/models/site_import.py b/backend/app/models/site_import.pyindex 0e8c91ab..40925dfd 100644--- a/backend/app/models/site_import.py+++ b/backend/app/models/site_import.py@@ -10,6 +10,7 @@ import jsonfrom datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixin# Formats the importer registry may grow to support. 'cpanel' ships first;# the others plug into the same pipeline (see app/services/site_importers/).@@ -22,7 +23,7 @@ VALID_STATUSES = ()-class SiteImport(db.Model):+class SiteImport(JsonColumnMixin, db.Model):__tablename__ = 'site_imports'id = db.Column(db.Integer, primary_key=True)@@ -48,35 +49,26 @@ class SiteImport(db.Model):updated_at = db.Column(db.DateTime, default=datetime.utcnow,onupdate=datetime.utcnow)- # ── JSON helpers ──- @staticmethod- def _loads(raw, default):- try:- value = json.loads(raw) if raw else default- except (ValueError, TypeError):- return default- return value if isinstance(value, type(default)) else default-def get_source(self):- return self._loads(self.source, {})+ return self._json_read('source', expect=dict)def set_source(self, value):self.source = json.dumps(value or {})def get_options(self):- return self._loads(self.options, {})+ return self._json_read('options', expect=dict)def set_options(self, value):self.options = json.dumps(value or {})def get_analysis(self):- return self._loads(self.analysis, {})+ return self._json_read('analysis', expect=dict)def set_analysis(self, value):self.analysis = json.dumps(value or {})def get_result(self):- return self._loads(self.result, {})+ return self._json_read('result', expect=dict)def set_result(self, value):self.result = json.dumps(value or {})diff --git a/backend/app/models/system_settings.py b/backend/app/models/system_settings.pyindex 04ee92cb..20915d57 100644--- a/backend/app/models/system_settings.py+++ b/backend/app/models/system_settings.py@@ -1,8 +1,9 @@from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixin-class SystemSettings(db.Model):+class SystemSettings(JsonColumnMixin, db.Model):"""Key-value store for system-wide settings."""__tablename__ = 'system_settings'@@ -26,8 +27,8 @@ class SystemSettings(db.Model):if self.value_type == 'integer':return int(self.value)if self.value_type == 'json':- import json- return json.loads(self.value)+ # Corrupt JSON degrades to None instead of raising (plan 77 B4).+ return self._json_read('value', None)return self.valuedef set_typed_value(self, value):diff --git a/backend/app/models/user.py b/backend/app/models/user.pyindex 27d56aa1..285e51c8 100644--- a/backend/app/models/user.py+++ b/backend/app/models/user.py@@ -161,11 +161,9 @@ class User(JsonColumnMixin, db.Model):"""Return resolved permissions: custom if set, otherwise role template."""if self.role == self.ROLE_ADMIN:return self.ROLE_PERMISSION_TEMPLATES['admin']- if self.permissions:- try:- return json.loads(self.permissions)- except (json.JSONDecodeError, TypeError):- pass+ custom = self._json_read('permissions', None)+ if custom is not None:+ return customreturn self.ROLE_PERMISSION_TEMPLATES.get(self.role, {})def set_permissions(self, perms_dict):diff --git a/backend/app/models/webhook_gateway.py b/backend/app/models/webhook_gateway.pyindex 7bbafa03..a9f6ee7f 100644--- a/backend/app/models/webhook_gateway.py+++ b/backend/app/models/webhook_gateway.py@@ -1,4 +1,3 @@-import jsonimport hmacimport hashlibimport base64@@ -88,7 +87,7 @@ class WebhookDelivery(JsonColumnMixin, db.Model):'id': self.id,'endpoint_id': self.endpoint_id,'event_id': self.event_id,- 'payload': json.loads(self.payload) if self.payload else None,+ 'payload': self._json_read('payload', None),'signature_valid': self.signature_valid,'status': self.status,'response_status': self.response_status,diff --git a/backend/app/models/wordpress_site.py b/backend/app/models/wordpress_site.pyindex a8c73e5c..c3eb1231 100644--- a/backend/app/models/wordpress_site.py+++ b/backend/app/models/wordpress_site.py@@ -9,8 +9,8 @@ Extended models for WordPress-specific functionality including:from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import TimestampMixin-import json# DatabaseSnapshot + SyncJob were relocated to app/models/db_snapshot.py# (plan 52 Phase 1 — generic snapshot/sync machinery no longer owned by the WP@@ -20,7 +20,7 @@ import jsonfrom app.models.db_snapshot import DatabaseSnapshot, SyncJob # noqa: F401-class WordPressSite(TimestampMixin, db.Model):+class WordPressSite(JsonColumnMixin, TimestampMixin, db.Model):"""Extended WordPress-specific data linked to Application."""__tablename__ = 'wordpress_sites'@@ -137,13 +137,13 @@ class WordPressSite(TimestampMixin, db.Model):'db_prefix': self.db_prefix,'git_repo_url': self.git_repo_url,'git_branch': self.git_branch,- 'git_paths': json.loads(self.git_paths) if self.git_paths else None,+ 'git_paths': self._json_read('git_paths', None),'auto_deploy': self.auto_deploy,'last_deploy_commit': self.last_deploy_commit,'last_deploy_at': self.last_deploy_at.isoformat() if self.last_deploy_at else None,'is_production': self.is_production,'production_site_id': self.production_site_id,- 'sync_config': json.loads(self.sync_config) if self.sync_config else None,+ 'sync_config': self._json_read('sync_config', None),'environment_type': self.environment_type,'multidev_branch': self.multidev_branch,'is_locked': self.is_locked,@@ -152,8 +152,8 @@ class WordPressSite(TimestampMixin, db.Model):'lock_expires_at': self.lock_expires_at.isoformat() if self.lock_expires_at else None,'compose_project_name': self.compose_project_name,'container_prefix': self.container_prefix,- 'resource_limits': json.loads(self.resource_limits) if self.resource_limits else None,- 'tags': json.loads(self.tags) if self.tags else [],+ 'resource_limits': self._json_read('resource_limits', None),+ 'tags': self._json_read('tags', []),'basic_auth_enabled': self.basic_auth_enabled,'basic_auth_user': self.basic_auth_user,'health_status': self.health_status,@@ -163,7 +163,7 @@ class WordPressSite(TimestampMixin, db.Model):'disk_usage_updated_at': self.disk_usage_updated_at.isoformat() if self.disk_usage_updated_at else None,'last_vuln_scan_at': self.last_vuln_scan_at.isoformat() if self.last_vuln_scan_at else None,'auto_update_schedule': self.auto_update_schedule,- 'auto_update_exclude': json.loads(self.auto_update_exclude) if self.auto_update_exclude else [],+ 'auto_update_exclude': self._json_read('auto_update_exclude', []),'auto_sync_schedule': self.auto_sync_schedule,'auto_sync_enabled': self.auto_sync_enabled,'created_at': self.created_at.isoformat() if self.created_at else None,@@ -238,7 +238,7 @@ class WordPressVulnerability(db.Model):return f'<WordPressVulnerability {self.id} {self.source}:{self.slug} {self.severity}>'-class WordPressUpdateRun(db.Model):+class WordPressUpdateRun(JsonColumnMixin, db.Model):"""A record of a safe-update run: snapshot -> update -> health-check -> rollback."""__tablename__ = 'wordpress_update_runs'@@ -261,7 +261,7 @@ class WordPressUpdateRun(db.Model):'site_id': self.site_id,'status': self.status,'trigger': self.trigger,- 'details': json.loads(self.details) if self.details else {},+ 'details': self._json_read('details'),'error': self.error,'started_at': self.started_at.isoformat() if self.started_at else None,'finished_at': self.finished_at.isoformat() if self.finished_at else None,@@ -271,7 +271,7 @@ class WordPressUpdateRun(db.Model):return f'<WordPressUpdateRun {self.id} site={self.site_id} {self.status}>'-class WordPressReport(db.Model):+class WordPressReport(JsonColumnMixin, db.Model):"""A persisted monthly client report for a WordPress site (#33 — agencyreports slice): a point-in-time snapshot of the site's uptime, incidents,update runs, backups, and security posture for one calendar month.@@ -310,7 +310,7 @@ class WordPressReport(db.Model):'period_label': self.period_label,'period_start': self.period_start.isoformat() if self.period_start else None,'period_end': self.period_end.isoformat() if self.period_end else None,- 'data': json.loads(self.data) if self.data else {},+ 'data': self._json_read('data'),'generated_at': self.generated_at.isoformat() if self.generated_at else None,}diff --git a/backend/app/models/workflow.py b/backend/app/models/workflow.pyindex 935fcdc6..4a300d74 100644--- a/backend/app/models/workflow.py+++ b/backend/app/models/workflow.py@@ -1,10 +1,10 @@from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import TimestampMixin-import json-class Workflow(TimestampMixin, db.Model):+class Workflow(JsonColumnMixin, TimestampMixin, db.Model):__tablename__ = 'workflows'id = db.Column(db.Integer, primary_key=True)@@ -37,26 +37,26 @@ class Workflow(TimestampMixin, db.Model):'id': self.id,'name': self.name,'description': self.description,- 'nodes': json.loads(self.nodes) if self.nodes else [],- 'edges': json.loads(self.edges) if self.edges else [],- 'viewport': json.loads(self.viewport) if self.viewport else None,+ 'nodes': self._json_read('nodes', []),+ 'edges': self._json_read('edges', []),+ 'viewport': self._json_read('viewport', None),'is_active': self.is_active,'trigger_type': self.trigger_type,- 'trigger_config': json.loads(self.trigger_config) if self.trigger_config else {},+ 'trigger_config': self._json_read('trigger_config'),'last_run_at': self.last_run_at.isoformat() if self.last_run_at else None,'last_status': self.last_status,'created_at': self.created_at.isoformat() if self.created_at else None,'updated_at': self.updated_at.isoformat() if self.updated_at else None,'user_id': self.user_id,- 'node_count': len(json.loads(self.nodes)) if self.nodes else 0,- 'edge_count': len(json.loads(self.edges)) if self.edges else 0+ 'node_count': len(self._json_read('nodes', [])),+ 'edge_count': len(self._json_read('edges', []))}def __repr__(self):return f'<Workflow {self.name}>'-class WorkflowExecution(db.Model):+class WorkflowExecution(JsonColumnMixin, db.Model):__tablename__ = 'workflow_executions'id = db.Column(db.Integer, primary_key=True)@@ -77,8 +77,8 @@ class WorkflowExecution(db.Model):'workflow_id': self.workflow_id,'status': self.status,'trigger_type': self.trigger_type,- 'context': json.loads(self.context) if self.context else {},- 'results': json.loads(self.results) if self.results else {},+ 'context': self._json_read('context'),+ 'results': self._json_read('results'),'started_at': self.started_at.isoformat() if self.started_at else None,'completed_at': self.completed_at.isoformat() if self.completed_at else None,'duration': (self.completed_at - self.started_at).total_seconds() if self.completed_at else Nonediff --git a/backend/app/models/workspace.py b/backend/app/models/workspace.pyindex 1d2a0428..4dd5c24b 100644--- a/backend/app/models/workspace.py+++ b/backend/app/models/workspace.py@@ -1,10 +1,11 @@from datetime import datetimefrom app import db+from app.models.json_column_mixin import JsonColumnMixinfrom app.models.mixins import TimestampMixinimport json-class Workspace(TimestampMixin, db.Model):+class Workspace(JsonColumnMixin, TimestampMixin, db.Model):"""Isolated container for servers, users, and settings."""__tablename__ = 'workspaces'@@ -40,7 +41,7 @@ class Workspace(TimestampMixin, db.Model):@propertydef settings(self):- return json.loads(self.settings_json) if self.settings_json else {}+ return self._json_read('settings_json')@settings.setterdef settings(self, v):@@ -102,7 +103,7 @@ class WorkspaceMember(db.Model):}-class WorkspaceApiKey(db.Model):+class WorkspaceApiKey(JsonColumnMixin, db.Model):"""API keys scoped to a single workspace."""__tablename__ = 'workspace_api_keys'@@ -120,7 +121,7 @@ class WorkspaceApiKey(db.Model):@propertydef scopes(self):- return json.loads(self.scopes_json) if self.scopes_json else []+ return self._json_read('scopes_json', [])@scopes.setterdef scopes(self, v):diff --git a/backend/tests/test_json_column_mixin.py b/backend/tests/test_json_column_mixin.pyindex f4e5d82e..d419b31a 100644--- a/backend/tests/test_json_column_mixin.py+++ b/backend/tests/test_json_column_mixin.py@@ -89,12 +89,67 @@ def test_falsy_writes_the_columns_empty_form_when_declared():def test_converted_models_inherit_the_mixin():"""A model converted back to a hand-rolled copy is the second doorreopening — the plan's thesis. Pin the opt-in list."""+ from app.models.agent_plugin import AgentPlugin, AgentPluginInstall+ from app.models.ai import AiConversation, AiMessage, AiPendingAction+ from app.models.application import Applicationfrom app.models.audit_log import AuditLogfrom app.models.backup_run import BackupRun+ from app.models.cloud_server import CloudServer+ from app.models.db_snapshot import DatabaseSnapshot, SyncJob+ from app.models.deployment import DeploymentDiff+ from app.models.deployment_job import DeploymentJob, DeploymentJobLog+ from app.models.dns_zone import DNSZone+ from app.models.environment_activity import EnvironmentActivity+ from app.models.host_snapshot import HostSnapshot+ from app.models.image_scan import SbomArtifact+ from app.models.plugin import InstalledPlugin+ from app.models.project import Project+ from app.models.promotion_job import PromotionJob+ from app.models.registrar_connection import RegistrarConnection+ from app.models.server_onboarding_log import ServerOnboardingLog+ from app.models.server_survey import ServerSurvey+ from app.models.server_template import ServerTemplate, ServerTemplateAssignment+ from app.models.site_import import SiteImport+ from app.models.system_settings import SystemSettingsfrom app.models.user import User-- for model in (AuditLog, BackupRun, User):- assert issubclass(model, JsonColumnMixin)+ from app.models.wordpress_site import (+ WordPressReport,+ WordPressSite,+ WordPressUpdateRun,+ )+ from app.models.workflow import Workflow, WorkflowExecution+ from app.models.workspace import Workspace, WorkspaceApiKey++ adopters = (+ AgentPlugin, AgentPluginInstall,+ AiConversation, AiMessage, AiPendingAction,+ Application,+ AuditLog,+ BackupRun,+ CloudServer,+ DatabaseSnapshot, SyncJob,+ DeploymentDiff,+ DeploymentJob, DeploymentJobLog,+ DNSZone,+ EnvironmentActivity,+ HostSnapshot,+ SbomArtifact,+ InstalledPlugin,+ Project,+ PromotionJob,+ RegistrarConnection,+ ServerOnboardingLog,+ ServerSurvey,+ ServerTemplate, ServerTemplateAssignment,+ SiteImport,+ SystemSettings,+ User,+ WordPressSite, WordPressUpdateRun, WordPressReport,+ Workflow, WorkflowExecution,+ Workspace, WorkspaceApiKey,+ )+ for model in adopters:+ assert issubclass(model, JsonColumnMixin), model.__name__def test_a_converted_model_end_to_end(app):diff --git a/backend/tests/test_models_json_one_door.py b/backend/tests/test_models_json_one_door.pynew file mode 100644index 00000000..4d7bf394--- /dev/null+++ b/backend/tests/test_models_json_one_door.py@@ -0,0 +1,36 @@+"""Plan 77 B4 ratchet: models parse JSON through ONE door.++Every hand-rolled ``json.loads`` in a model file is a bypass of+``JsonColumnMixin._json_read`` — a place where a corrupt row raises and+500s every endpoint that serializes the model instead of degrading to the+accessor's default. Plan 77 B4 converted the last of them; this ratchet+keeps the count at zero. If this test fails, use ``self._json_read(...)``+(inherit ``JsonColumnMixin`` first in the bases) instead of ``json.loads``.+"""++from pathlib import Path++MODELS_DIR = Path(__file__).resolve().parents[1] / 'app' / 'models'++# The mixin is the one place allowed to call json.loads.+ALLOWED = {'json_column_mixin.py'}+++def test_no_model_file_hand_rolls_json_loads():+ offenders = {}+ for path in sorted(MODELS_DIR.glob('*.py')):+ if path.name in ALLOWED:+ continue+ lines = [+ f'{path.name}:{lineno}'+ for lineno, line in enumerate(+ path.read_text(encoding='utf-8').splitlines(), start=1+ )+ if 'json.loads(' in line+ ]+ if lines:+ offenders[path.name] = lines+ assert not offenders, (+ 'json.loads( in model files outside json_column_mixin.py — '+ f'use self._json_read instead: {offenders}'+ )