From 1499135409818334b18002af916d8b12babce712 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Wed, 3 Dec 2025 10:29:52 +0100 Subject: [PATCH] fix: prevent invalid paths from being saved to database MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move compose file validation BEFORE database save to prevent invalid base directory and docker compose location values from being persisted when validation fails. Changes: - Move compose file validation before $this->application->save() - Restore original values when validation fails - Add resetErrorBag() to clear stale validation errors This fixes two bugs: 1. Invalid paths were saved to DB even when validation failed 2. Error messages persisted after correcting to valid path 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/Livewire/Project/Application/General.php | 24 +++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index 56d45ae19..46a459fe2 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -779,6 +779,7 @@ public function submit($showToaster = true) try { $this->authorize('update', $this->application); + $this->resetErrorBag(); $this->validate(); $oldPortsExposes = $this->application->ports_exposes; @@ -825,23 +826,30 @@ public function submit($showToaster = true) $this->application->publish_directory = $this->publishDirectory; } - $this->application->save(); - if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE' && ! $this->application->settings->is_container_label_readonly_enabled) { - $this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n"); - $this->application->custom_labels = base64_encode($this->customLabels); - $this->application->save(); - } - - // Validate docker compose file path when base directory OR compose location changes + // Validate docker compose file path BEFORE saving to database + // This prevents invalid paths from being persisted when validation fails if ($this->buildPack === 'dockercompose' && ($oldDockerComposeLocation !== $this->dockerComposeLocation || $oldBaseDirectory !== $this->baseDirectory)) { $compose_return = $this->loadComposeFile(showToast: false); if ($compose_return instanceof \Livewire\Features\SupportEvents\Event) { + // Restore original values - don't persist invalid data + $this->baseDirectory = $oldBaseDirectory; + $this->dockerComposeLocation = $oldDockerComposeLocation; + $this->application->base_directory = $oldBaseDirectory; + $this->application->docker_compose_location = $oldDockerComposeLocation; + return; } } + $this->application->save(); + if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE' && ! $this->application->settings->is_container_label_readonly_enabled) { + $this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n"); + $this->application->custom_labels = base64_encode($this->customLabels); + $this->application->save(); + } + if ($oldPortsExposes !== $this->portsExposes || $oldIsContainerLabelEscapeEnabled !== $this->isContainerLabelEscapeEnabled) { $this->resetDefaultLabels(); }