Evolve converts/validates again not changed fields

Open
#1,126 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
tooling

Research direction

The only entry point named is attrs.evolve; start by tracing its implementation and the existing tests around evolve, then reproduce the frozen Settings example. Done means evolving only user does not reconvert or revalidate unchanged pwd, with regression coverage for that behavior.

Written by the indexing model from the issue text.

Description

Feature

Here's the usecase:

def decrypt_secret(value):
    return ...

@attrs.frozen
class Settings:
    user: str
    pwd: str = attrs.field(converter=decrypt_secret)

sett = Settings(user="name", pwd=<encrypted_value>)
sett.pwd  # already decrypted value

attrs.evolve(sett, user="name2")

This will fail, because it tries to decrypt already decrypted value, although the field pwd not changed at all.

Probably it is a wrong behaviour to convert/validate not changed fields.

Didn't find how to avoid converting/validating in this case.

Dominant language
Python
Stars
5.8k
Forks
480
Avg merge
2h 15m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-attrs/attrs

All issues in python-attrs/attrs

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.