Skip to content

Conversation

@agriyakhetarpal
Copy link
Contributor

Description

The test_remove_all_json test, as follows:

@pytest.mark.parametrize("subcommand", ["remove", "uninstall"])
def test_remove_all_json(
subcommand: str, conda_cli: CondaCLIFixture, tmp_env: TmpEnvFixture
):
# Test that the json output is valid
# regression test for #13019
with tmp_env("ca-certificates") as prefix:
out, err, code = conda_cli(subcommand, "--prefix", prefix, "--all", "--json")
json_obj = json.loads(out)
assert "UNLINK" in json_obj["actions"]
assert not err
assert not code

runs conda remove --all --json. This command calls conda.common.serialize.json.dumps(). However, since there is no native support for frozendict, the system falls back to the deprecated monkeypatched JSON encoder rather than CondaJSONEncoder. This is why running this test as part of the suite generates the following warning:

PendingDeprecationWarning: Monkey-patching json.JSONEncoder to support frozendict is pending deprecation and will be removed in version 26.9

This PR adds support for serialising immutable dictionaries in CondaJSONEncoder. I have separated this change from #15525 (originally #12771) to reduce its diff.

Checklist - did you ...

  • [⚠️ Do we need one?] Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@agriyakhetarpal agriyakhetarpal requested a review from a team as a code owner December 17, 2025 22:02
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Dec 17, 2025
@github-project-automation github-project-automation bot moved this to 🆕 New in 🔎 Review Dec 17, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 17, 2025

CodSpeed Performance Report

Merging #15532 will not alter performance

Comparing agriyakhetarpal:deprecation-warnings-as-errors-pt2 (fe0080c) with main (9a146a8)

Summary

✅ 23 untouched
⏩ 21 skipped1

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@travishathaway
Copy link
Contributor

@agriyakhetarpal,

I looked around on this and learned that it's not actually necessary to add this our CondaJSONEncoder because this is already being accounted for in frozendict itself.

Please see the following links for more information:

Conda currently has a requirement of frozendict>=2.4.2, so this shouldn't be an issue. When we finally remove the deprecated code paths, everything should JustWork™️ ✨ .

jezdez
jezdez previously approved these changes Dec 18, 2025
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Approved in 🔎 Review Dec 18, 2025
@travishathaway
Copy link
Contributor

@jezdez,

Do you have any feedback on my comment? Am I correct in thinking that this pull request isn't necessary?

@jezdez
Copy link
Member

jezdez commented Dec 18, 2025

Oh huh, that comment didn't load in the tab I had this issue open before posting my comment. This changes things!

Looking at the change upstream, this monkeypatch seems like a pretty bad idea, Marco-Sulla/python-frozendict@v2.3.5...v2.3.6#diff-f9ec75e660 and we added the pending deprecation note in #14709 specifically to stop monkeypatching locally as well. I would say this change here is technically correct, but you're right that the monkeypatching in https://github.com/Marco-Sulla/python-frozendict/blob/master/src/frozendict/monkeypatch.py seems to cover most cases. I wonder if there is any risk involved with the change in #14709 that we hadn't thought about. This is why monkeypatching is never a good API strategy!

@jezdez
Copy link
Member

jezdez commented Dec 18, 2025

This makes me want to stop relying on frozendict btw.

@jezdez
Copy link
Member

jezdez commented Dec 18, 2025

I wonder if https://peps.python.org/pep-0814/ goes anywhere and if there are backports? What about https://adamj.eu/tech/2022/01/05/how-to-make-immutable-dict-in-python/ should we simply roll it ourselves?

@travishathaway
Copy link
Contributor

This makes me want to stop relying on frozendict btw.

My thoughts exactly! 😬

@travishathaway
Copy link
Contributor

I wonder if https://peps.python.org/pep-0814/ goes anywhere and if there are backports? What about https://adamj.eu/tech/2022/01/05/how-to-make-immutable-dict-in-python/ should we simply roll it ourselves?

Maybe we should just create a separate issue for this work and not merge this pull request?

@travishathaway
Copy link
Contributor

@kenodegard, maybe you have some thoughts on this. Couldn't help but notice your name as I was skimming through the release notes in frozendict.

@agriyakhetarpal
Copy link
Contributor Author

Thanks for the conversation, y'all! For now, I'll remove this change from #15525 and replace it with a deprecated_call there, and I'll mark this pull request as a draft. I don't yet see a backport for PEP 814 work, so maybe having our own frozendict in auxlib is the best idea.

@agriyakhetarpal agriyakhetarpal marked this pull request as draft December 18, 2025 21:22
@agriyakhetarpal
Copy link
Contributor Author

This PR has been superseded by the change I described in #15525 (comment). Thanks, everyone!

@github-project-automation github-project-automation bot moved this from ✅ Approved to 🏁 Done in 🔎 Review Dec 19, 2025
@agriyakhetarpal agriyakhetarpal deleted the deprecation-warnings-as-errors-pt2 branch December 19, 2025 16:55
@agriyakhetarpal agriyakhetarpal restored the deprecation-warnings-as-errors-pt2 branch December 20, 2025 10:16
@agriyakhetarpal
Copy link
Contributor Author

I'm reopening this PR as per @beckermr's suggestion in #15525 (comment). The support that frozendict provides for custom encoders like ours is a bit finicky – mainly because it requires us to mess with the import order and ensure that frozendict is imported before json.

@github-project-automation github-project-automation bot moved this from 🏁 Done to 🏗️ In Progress in 🔎 Review Dec 20, 2025
@agriyakhetarpal agriyakhetarpal marked this pull request as ready for review December 20, 2025 10:20
@travishathaway
Copy link
Contributor

Hi @beckermr,

Thanks for chiming in here and looking into this too. I read your feedback over here and think it's reasonable to include this pull request. Inspecting the type here doesn't have a huge cost and we add additional tests to ensure this expect behavior works.

Because of those reasons, I'll go ahead merge this pull request. But, with that being said, I think it's worth it to research what we could do instead of relying on a dependency that monkey patches the standard library. I think we can all agree that that's not a good idea, so I will create an issue specifically for that work.

@github-project-automation github-project-automation bot moved this from 🏗️ In Progress to ✅ Approved in 🔎 Review Dec 22, 2025
@travishathaway travishathaway merged commit 5a74197 into conda:main Dec 22, 2025
71 checks passed
@github-project-automation github-project-automation bot moved this from ✅ Approved to 🏁 Done in 🔎 Review Dec 22, 2025
@agriyakhetarpal agriyakhetarpal deleted the deprecation-warnings-as-errors-pt2 branch December 22, 2025 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed [bot] added once the contributor has signed the CLA

Projects

Status: 🏁 Done

Development

Successfully merging this pull request may close these issues.

5 participants