Page MenuHomeVyOS Platform

Fix mutable default argument bug in Config API methods
Closed, ResolvedPublic

Description

Four Config class methods use default=[] as a parameter default, which is the classic Python pitfall: the empty list is created once at function-definition time and shared across all calls. Any mutation to the default leaks across callers and produces silent state corruption.

Methods affected

In python/vyos/config.py:

  • return_values
  • list_nodes
  • return_effective_values
  • list_effective_nodes

Fix

Replace default=[] with default=None and add an explicit guard inside the function body:

def return_values(self, path, default=None):
    if default is None:
        default = []
    ...

This preserves the caller-facing semantics (no default argument → empty list back) while removing the shared-state bug.

GitHub PR

https://github.com/vyos/vyos-1x/pull/5075

Details

Version
rolling
Issue type
Bug (incorrect behavior)