---
title: "python-benedict: self-referencing dicts in Python | VulCode"
description: "A fix to python-benedict, a Python dict subclass: assigning a dict into its own nested descendant now raises a clear ValueError instead of a RecursionError."
url: "https://vulcode.com/en/opensource/contributions/python-benedict"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

fabiocaccamo/python-benedict

# python-benedict

A Python dict subclass with key path access and built-in reading and writing of many formats, such as JSON, YAML, TOML and CSV.

[See the repository](https://github.com/fabiocaccamo/python-benedict) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Python
- **GitHub stars**: 1,606
- **Merged changes**: 1

## What we changed

Assigning a dict into its own nested descendant now ends in a clear ValueError instead of an uncontrolled RecursionError.

### What this work shows

- Cycle detection in recursion

- Python dict subclasses

- Regression tests with unittest

What was broken

### A second self-assignment blew the stack

After test.a.b.c = test, a further assignment such as test.a.b.d.e = test ended in a RecursionError, and according to the issue it could crash a Jupyter kernel. _get_dict_or_value() unwrapped nested dicts recursively with no cycle detection.

How we fixed it

### A cycle guard on the call stack

_get_dict_or_value() records the id() of each dict it is unwrapping and drops it on exit, so shared references are not mistaken for cycles. When it meets a dict already being unwrapped, it raises a descriptive ValueError at once, and tests also cover normal nesting and self-assignment under a new key.

[#597](https://github.com/fabiocaccamo/python-benedict/pull/597)

## Merged change 1

- [#597 Fix RecursionError when assigning a benedict into its own nested descendant (#592) Merged 29 September 2026](https://github.com/fabiocaccamo/python-benedict/pull/597)

## What it taught us

Structures that can reference themselves need cycle detection in every recursive walk. When full cycle support would mean changes in many places, a clear error at one point beats a stack overflow that can kill the process.

[More about this technology: Python](https://vulcode.com/en/technologies/python)

## Other projects we write code for

- [**more-itertools** Python · 4,106 stars A Python library with more routines for operating on iterables, beyond the itertools module.](https://vulcode.com/en/opensource/contributions/more-itertools)

- [**funcy** Python · 3,507 stars A collection of practical functional tools for Python, including helpers for sequences, collections and iterators.](https://vulcode.com/en/opensource/contributions/funcy)

- [**pydash** Python · 1,449 stars A Python utility library modelled on Lo-Dash from JavaScript. It offers ready-made operations on lists, dicts and strings in a functional style.](https://vulcode.com/en/opensource/contributions/pydash)

- [**pydantic-extra-types** Python · 345 stars Extra types for data validation in Pydantic, the popular Python library: MAC addresses, time zones, semantic versions, ULIDs and many more.](https://vulcode.com/en/opensource/contributions/pydantic-extra-types)

- [**pytimeparse** Python · 296 stars A small Python module that turns time expressions such as 1h30m or 1:24 into a number of seconds.](https://vulcode.com/en/opensource/contributions/pytimeparse)

- [**Node.js** JavaScript · 123,955 stars The JavaScript runtime built on V8 that runs servers, command line tools and front-end build pipelines. It ships a built-in node:sqlite module for working with SQLite databases.](https://vulcode.com/en/opensource/contributions/nodejs)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
