Skip to content

Conversation

@EwoutH
Copy link
Contributor

@EwoutH EwoutH commented Nov 7, 2025

Python 3.14 enforces stricter rules around dictionary mutation during iteration. The BaseSettings class in minisettings.py was modifying cls.dict via setattr() while iterating over it, causing a RuntimeError.

Fixed by creating a snapshot of dictionary items before iteration in both init_subclass and init methods using list(cls.dict.items()).

Fixes the import error:
RuntimeError: dictionary changed size during iteration

Closes #1107. Cherrypick from #1108.

Python 3.14 enforces stricter rules around dictionary mutation during iteration. The BaseSettings class in minisettings.py was modifying cls.__dict__ via setattr() while iterating over it, causing a RuntimeError.

Fixed by creating a snapshot of dictionary items before iteration in both __init_subclass__ and __init__ methods using list(cls.__dict__.items()).

Fixes the import error:
RuntimeError: dictionary changed size during iteration
@EwoutH EwoutH mentioned this pull request Nov 7, 2025
@maartenbreddels maartenbreddels merged commit 4bf31d5 into widgetti:master Nov 10, 2025
55 of 56 checks passed
@maartenbreddels
Copy link
Contributor

Thanks!

@EwoutH
Copy link
Contributor Author

EwoutH commented Nov 10, 2025

Thanks for merging!

Could you tag a new release? Maybe this already solves our problems.

@maartenbreddels
Copy link
Contributor

I just released 1.55, which includes this fix. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RuntimeError: dictionary changed size during iteration in minisettings.py on Python 3.14

2 participants