Skip to content

mgr/PyFormatter: make cached dicts read-only - #74054

Open
NitzanMordhai wants to merge 2 commits into
ceph:mainfrom
NitzanMordhai:wip-nitzan-mgr-pyformatterro-readonly-dict
Open

NitzanMordhai wants to merge 2 commits into
ceph:mainfrom
NitzanMordhai:wip-nitzan-mgr-pyformatterro-readonly-dict

Conversation

@NitzanMordhai

@NitzanMordhai NitzanMordhai commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

PyFormatterRO is meant to freeze cached get() results, but
convert_dict_to_proxy() built a plain dict, so dicts stayed mutable and
a write by one module leaked into the cache shared by all modules.

Convert dicts to ReadOnlyDict, a dict subclass whose mutating methods
raise TypeError. It stays a real dict, so json.dumps() and isinstance()
keep working (a mappingproxy would break both), and copy/deepcopy
return a plain, writable dict. Callers that need to modify the data
should use get(..., mutable=True).

Fixes: https://tracker.ceph.com/issues/83314

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

add_id() wrote 'id' into the OSD dicts returned by mgr.get('osd_map'),
and Osd.list() then added stats, tree and status keys to the same
objects. With the mgr API cache enabled those dicts are shared with
every other module, so the dashboard was silently modifying cached
data. Return a shallow copy instead.

Fixes: https://tracker.ceph.com/issues/83314
Signed-off-by: Nitzan Mordechai <[email protected]>
Assisted-by: Claude
Comment thread src/mgr/PyFormatter.cc Resolved
@github-project-automation github-project-automation Bot moved this from New to Reviewer approved in Ceph-Dashboard Nov 20, 2026
PyFormatterRO is meant to freeze cached get() results, but
convert_dict_to_proxy() built a plain dict, so dicts stayed mutable and
a write by one module leaked into the cache shared by all modules.

Convert dicts to ReadOnlyDict, a dict subclass whose mutating methods
raise TypeError. It stays a real dict, so json.dumps() and isinstance()
keep working (a mappingproxy would break both), and copy/deepcopy
return a plain, writable dict. Callers that need to modify the data
should use get(..., mutable=True).

Fixes: https://tracker.ceph.com/issues/83314
Signed-off-by: Nitzan Mordechai <[email protected]>
Assisted-by: Claude
@NitzanMordhai
NitzanMordhai force-pushed the wip-nitzan-mgr-pyformatterro-readonly-dict branch from 3916ff9 to 6f74b1b Compare November 22, 2026 11:09
Comment thread src/mgr/PyFormatter.cc
static const char* src = R"(
class ReadOnlyDict(dict):
def _ro(self, *args, **kwargs):
raise TypeError('read-only; use get(..., mutable=True)')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comment here: it feels unusual that an exception in a class is referring to some other method in a different class (get()).

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath37-testing-20261124.044935-main.

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

Projects

Status: Reviewer approved

Development

Successfully merging this pull request may close these issues.

3 participants