Skip to content

Commit 3c03c54

Browse files
committed
fix: fixed the issue of rendering templates being discarded when saving configurations
(cherry picked from commit 1e11102497a7bf22f056e7f6986db87dd15b2451)
1 parent a2c20e8 commit 3c03c54

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

agentkit/toolkit/config/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
# Default image tag placeholder for timestamped builds
3232
DEFAULT_IMAGE_TAG = "{{timestamp}}"
33+
DEFAULT_IMAGE_TAG_TEMPLATE = "{{timestamp}}"
3334

3435
# Global configuration constants
3536
GLOBAL_CONFIG_DIR = Path.home() / ".agentkit"

agentkit/toolkit/config/dataclass_utils.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,13 @@ def from_dict(cls: Type[T], data: Dict[str, Any], skip_render: bool = False) ->
133133
instance = apply_global_config_defaults(instance, data)
134134
after = instance.to_dict()
135135
if before != after:
136-
# Compute diff of updated fields
137136
diff = {k: (before.get(k), after.get(k)) for k in after.keys() if before.get(k) != after.get(k)}
138137
logger.debug("from_dict: applied global defaults for %s; changes=%r", cls.__name__, diff)
139138
else:
140139
logger.debug("from_dict: applied global defaults for %s; no changes", cls.__name__)
141140
except ImportError:
142-
# Global config module unavailable
143141
logger.debug("from_dict: global_config not available; skipped applying globals for %s", cls.__name__)
144142
except Exception:
145-
# Global defaults application should not break overall flow
146143
logger.debug("from_dict: apply_global_config_defaults raised; ignored for %s", cls.__name__)
147144

148145
# Render template fields after globals/defaults. Skipped if skip_render is True.
@@ -213,19 +210,15 @@ def _render_template_fields(self):
213210
default_template,
214211
)
215212
field_value = default_template
216-
# Save original template string
217213
self._template_originals[field_info.name] = default_template
218-
# Mark value source
219214
try:
220215
if not hasattr(self, '_value_sources'):
221216
self._value_sources = {}
222217
self._value_sources[field_info.name] = 'default_template'
223218
except Exception:
224219
pass
225-
# Set template value first so there is a visible value even if rendering fails
226220
setattr(self, field_info.name, default_template)
227221
else:
228-
# No default_template; skip
229222
logger.debug("[%s] [template] field %s is Auto/empty and has no default_template -> skip", cfg_name, field_info.name)
230223
continue
231224

@@ -239,13 +232,7 @@ def _render_template_fields(self):
239232

240233
try:
241234
rendered = render_template(field_value)
242-
logger.debug(
243-
"[%s] [template] rendered field %s: %r -> %r",
244-
cfg_name,
245-
field_info.name,
246-
field_value,
247-
rendered,
248-
)
235+
logger.debug("[%s] [template] rendered field %s: %r -> %r", cfg_name, field_info.name, field_value, rendered)
249236
# Fail if unresolved placeholders remain
250237
if '{{' in str(rendered) and '}}' in str(rendered):
251238
error_msg = (
@@ -258,9 +245,6 @@ def _render_template_fields(self):
258245
if rendered != field_value:
259246
logger.debug("[%s] [template] apply rendered value for %s", cfg_name, field_info.name)
260247
setattr(self, field_info.name, rendered)
261-
# Extra logging for image_tag
262-
if field_info.name == "image_tag":
263-
logger.info("[%s] [template] image_tag final value: %r", cfg_name, getattr(self, field_info.name))
264248
except Exception as e:
265249
# Do not silently fallback on render failures; surface details
266250
error_type = type(e).__name__
@@ -320,18 +304,12 @@ def to_persist_dict(self) -> Dict[str, Any]:
320304
chosen = original_tpl if original_tpl is not None else current_value
321305
result[name] = chosen
322306
logger.debug("[persist] field=%s source=default_template original=%r current=%r -> write=%r", name, original_tpl, current_value, chosen)
323-
elif source == 'default':
324-
# Default source: persist current value
325-
result[name] = current_value
326-
logger.debug("[persist] field=%s source=default -> write=%r", name, current_value)
327-
elif source == 'local':
328-
# Local source: if it was a template input, prefer original template
307+
elif source == 'default' or source == 'local':
329308
if original_tpl is not None:
330309
result[name] = original_tpl
331-
logger.debug("[persist] field=%s source=local original_tpl exists -> write original=%r", name, original_tpl)
332310
else:
333311
result[name] = current_value
334-
logger.debug("[persist] field=%s source=local no original_tpl -> write current=%r", name, current_value)
312+
logger.debug("[persist] field=%s source=%s original=%r current=%r -> write=%r", name, source, original_tpl, current_value, result[name])
335313
else:
336314
# Unknown source: keep current value
337315
result[name] = current_value

agentkit/toolkit/config/strategy_configs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dataclasses import dataclass, field
22
from typing import Dict, List
33
from .dataclass_utils import AutoSerializableMixin
4-
from .constants import AUTO_CREATE_VE, DEFAULT_CR_NAMESPACE, DEFAULT_IMAGE_TAG, DEFAULT_WORKSPACE_NAME, DEFAULT_CR_INSTANCE_TEMPLATE_NAME, DEFAULT_TOS_BUCKET_TEMPLATE_NAME
4+
from .constants import AUTO_CREATE_VE, DEFAULT_CR_NAMESPACE, DEFAULT_IMAGE_TAG, DEFAULT_IMAGE_TAG_TEMPLATE, DEFAULT_WORKSPACE_NAME, DEFAULT_CR_INSTANCE_TEMPLATE_NAME, DEFAULT_TOS_BUCKET_TEMPLATE_NAME
55

66

77
@dataclass
@@ -45,7 +45,7 @@ class LocalStrategyConfig(AutoSerializableMixin):
4545
class HybridStrategyConfig(AutoSerializableMixin):
4646
"""Hybrid deployment strategy configuration combining local Docker and Volcano Engine services."""
4747
# User-configurable fields
48-
image_tag: str = field(default=DEFAULT_IMAGE_TAG, metadata={"system": True, "description": "Docker image tag", "icon": "🏷️", "render_template": True})
48+
image_tag: str = field(default=DEFAULT_IMAGE_TAG, metadata={"system": True, "description": "Docker image tag", "icon": "🏷️", "render_template": True, "default_template": DEFAULT_IMAGE_TAG_TEMPLATE})
4949

5050
# System internal fields (not visible to users during configuration)
5151
image_id: str = field(default="", metadata={"system": True, "description": "Docker image ID"})
@@ -108,7 +108,7 @@ class CloudStrategyConfig(AutoSerializableMixin):
108108
tos_object_url: str = field(default="", metadata={"system": True, "description": "TOS object URL for build artifact"})
109109

110110
# Container Registry (CR) configuration for Docker images
111-
image_tag: str = field(default=DEFAULT_IMAGE_TAG, metadata={"system": True, "description": "Docker image tag", "icon": "🏷️", "render_template": True})
111+
image_tag: str = field(default=DEFAULT_IMAGE_TAG, metadata={"system": True, "description": "Docker image tag", "icon": "🏷️", "render_template": True, "default_template": DEFAULT_IMAGE_TAG_TEMPLATE})
112112
cr_instance_name: str = field(default=AUTO_CREATE_VE, metadata={"description": "Container Registry instance name", "icon": "📦", "render_template": True, "default_template": DEFAULT_CR_INSTANCE_TEMPLATE_NAME, "aliases": ["ve_cr_instance_name"]})
113113
cr_namespace_name: str = field(default=DEFAULT_CR_NAMESPACE, metadata={"description": "Container Registry namespace", "icon": "📁", "render_template": True, "aliases": ["ve_cr_namespace_name"]})
114114
cr_repo_name: str = field(default="", metadata={"description": "Container Registry repository name (defaults to AgentKit project name)", "icon": "📋", "aliases": ["ve_cr_repo_name"]})

0 commit comments

Comments
 (0)