-
Notifications
You must be signed in to change notification settings - Fork 45
refactor: PythonGenerator.Generate mutates caller's AgentConfig via pointer #204
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Description
Description
PythonGenerator.Generate receives *common.AgentConfig and mutates several fields in-place:
// internal/cli/agent/frameworks/adk/python/generator.go
func (g *PythonGenerator) Generate(agentConfig *common.AgentConfig) error {
agentConfig.Name = validators.PythonSafeName(agentConfig.Name) // line 36
// ...
agentConfig.Framework = "adk" // line 51
agentConfig.Language = "python" // line 52
}The caller in init.go currently works correctly because it uses a separate agentName string variable for post-Generate output. However, any future code that reads agentConfig.Name after calling Generate would observe the transformed value (my_agent) instead of the original (my-agent).
This is a latent correctness risk - the function silently changes its input without the caller expecting it.
Suggested Fix
Work on a local copy inside Generate instead of mutating the caller's struct:
func (g *PythonGenerator) Generate(agentConfig *common.AgentConfig) error {
if agentConfig == nil {
return fmt.Errorf("agent config is required")
}
cfg := *agentConfig
cfg.Name = validators.PythonSafeName(agentConfig.Name)
cfg.Framework = "adk"
cfg.Language = "python"
// use cfg everywhere below
}Change Type
/kind cleanup
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels