Skip to content

get api for key with default value, always returns default value for nested keys #1216

@nvattikonda

Description

@nvattikonda

Describe the bug
conf.get('key', 'default_value') always returns default_value for nested keys

To Reproduce
conf = OmegaConf.create({"a": 1, "b": {"c": 2}})

Accessing an existing key

value_a = conf.get("a", 10) # Returns 1 because "a" exists
print(value_a) # Output: 1
value_b = conf.get("b.c", 20)
print(value_b) # Returns 20 instead of 2
value_b_correct = OmegaConf.select(conf, "b.c", default=25)
print(value_b_correct) # Returns 2 because "b.c" exists

Expected behavior
Expected behavior
value_b = conf.get("b.c", 20) # Return 2 similar to OmegaConf.select(conf, "b.c", default=25)

Additional context

  • OmegaConf version: v2.3.0
  • Python version: v3.12.10
  • Operating system: macOS, Darwin Kernel Version 24.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions