Support += and -= for multi-value fields in modify#6648
Conversation
|
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6648 +/- ##
==========================================
+ Coverage 72.44% 72.48% +0.04%
==========================================
Files 160 160
Lines 20690 20722 +32
Branches 3272 3281 +9
==========================================
+ Hits 14989 15021 +32
Misses 4976 4976
Partials 725 725
🚀 New features to boost your workflow:
|
|
I really love the feature idea and the straightforward syntax suggestion but don't really have time to look into it these days.... If I'm not mistaken this feature was requested already, maybe even multiple times. Do you mind looking up those issues or did you already and couldn't find them? |
snejus
left a comment
There was a problem hiding this comment.
Well done. I think we'd like ModifyOperation class to be a bit smarter and own all relevant methods, see my comments
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ModifyOperation: |
There was a problem hiding this comment.
I think this can be simplified to a NamedTuple.
| ) | ||
|
|
||
|
|
||
| def _apply_modify_operation(obj, field, mod, value): |
There was a problem hiding this comment.
I want this to be a method on ModifyOperation, e.g. def apply.
| key, operator = key[:-1], key[-1] | ||
| key = maybe_replace_legacy_field(key, is_album, modify=True) | ||
| mods[key] = val | ||
| mods[key] = ModifyOperation(operator, val) if operator else val |
There was a problem hiding this comment.
Let's only have ModifyOperations here! Simply set operator=None when we have no operator.
Description
Fixes #6587.
This PR adds
+=and-=support tobeet modifyfor multi-value fields.For example:
With this change,
genres+=FunkappendsFunkto the existinggenresvalues if it is not already present, whilegenres-=Bluesremoves only the exact valueBluesand preserves other values such asBlues Rock.The existing
field=valuereplacement behavior is preserved.Main behavior changes:
genres=Jazz; Bluesstill replaces the full field value as before.genres+=FunkappendsFunkto the existing multi-value field.genres+=Funkdoes not create duplicate values.genres-=Bluesremoves only the exact valueBlues.Bluesdoes not remove partial matches likeBlues Rock.+=and-=are rejected for scalar fields with a clear user-facing error.To Do
modifycommand documentation if maintainers prefer.Verification
Ran: