From c2dd480edd68e7fefa4778fe99cc39d796162e49 Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Sat, 30 May 2026 13:26:36 +0800 Subject: [PATCH] Fix Docker container variable compatibility with Pydantic models When updating project variables while Docker containers are running, the system now properly handles both dictionary-format variables and Pydantic Variable objects. This prevents AttributeError when containers are recreated after variable updates. Changes: - Modified DockerVM.create() to detect and handle Pydantic Variable objects - Updated _format_env() method to support both variable formats - Maintains backward compatibility with existing dictionary format Fixes error: AttributeError: 'Variable' object has no attribute 'get' --- gns3server/compute/docker/docker_vm.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/gns3server/compute/docker/docker_vm.py b/gns3server/compute/docker/docker_vm.py index 5219ad4c8..988d61cf3 100644 --- a/gns3server/compute/docker/docker_vm.py +++ b/gns3server/compute/docker/docker_vm.py @@ -511,8 +511,18 @@ class DockerVM(BaseNode): variables = [] for var in variables: - formatted = self._format_env(variables, var.get("value", "")) - params["Env"].append("{}={}".format(var["name"], formatted)) + # Handle both Pydantic Variable objects and dictionaries + if hasattr(var, "name"): + # Pydantic Variable object + var_name = var.name + var_value = getattr(var, "value", "") + else: + # Dictionary format + var_name = var.get("name", "") + var_value = var.get("value", "") + + formatted = self._format_env(variables, var_value) + params["Env"].append("{}={}".format(var_name, formatted)) if self._environment: for e in self._environment.strip().split("\n"): @@ -581,7 +591,17 @@ class DockerVM(BaseNode): def _format_env(self, variables, env): for variable in variables: - env = env.replace("${" + variable["name"] + "}", variable.get("value", "")) + # Handle both Pydantic Variable objects and dictionaries + if hasattr(variable, "name"): + # Pydantic Variable object + var_name = variable.name + var_value = getattr(variable, "value", "") + else: + # Dictionary format + var_name = variable.get("name", "") + var_value = variable.get("value", "") + + env = env.replace("${" + var_name + "}", var_value) return env def _format_extra_hosts(self, extra_hosts):