Skip to content

First attempt at fixing #3132.#3133

Merged
sampsyo merged 4 commits intomasterfrom
no_clobber
Jan 27, 2019
Merged

First attempt at fixing #3132.#3133
sampsyo merged 4 commits intomasterfrom
no_clobber

Conversation

@djl
Copy link
Copy Markdown
Member

@djl djl commented Jan 25, 2019

Add a new no_clobber config option that contains a list of "miscellaneous" metadata fields not to be overwritten by empty values.

I'm not entirely happy with the no_clobber name. Suggestions welcome.

Add a new `no_clobber` config option that contains a list of
"miscellaneous" metadata fields not to be overwritten by empty values.

I'm not entirely happy with the `no_clobber` name. Suggestions welcome.
Copy link
Copy Markdown
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Looks good! I just have a couple of small concerns about the name and the role this plays:

  • Putting a field on this list doesn't prevent clobbering altogether—it only prevents clobbering when the new value would be empty. So the name could mislead people into thinking that putting a field there "protects" it completely (i.e., never overwrites that field with anything).
  • There are other fields that have is not None checks in this function that aren't in the miscellaneous metadata list. For example, disctitle gets handled separately (for some reason), as do many other fields. So putting that field in this list won't have the intended effect.

'data_source',):
# Don't overwrite fields with empty values unless the
# field is explicitly allowed to be overwritten
clobber = field not in config['no_clobber'].get()
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.

A type assertion here might be useful: .as_str_seq() instead of .get().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

@djl
Copy link
Copy Markdown
Member Author

djl commented Jan 25, 2019

Putting a field on this list doesn't prevent clobbering altogether—it only prevents clobbering when the new value would be empty. So the name could mislead people into thinking that putting a field there "protects" it completely (i.e., never overwrites that field with anything).

Great point. I'm open to any suggestions for a better name. nullable_fields or something, perhaps?

There are other fields that have is not None checks in this function that aren't in the miscellaneous metadata list. For example, disctitle gets handled separately (for some reason), as do many other fields. So putting that field in this list won't have the intended effect.

Also a good point. Should all these fields be moved into the no_clobber list? They're track fields so they'll need to handled separately from the album fields, making no_clobber slightly more complicated.

@sampsyo
Copy link
Copy Markdown
Member

sampsyo commented Jan 26, 2019

Hmm... I’m not sure what the best course of action is. Maybe it would be simplest to invert the sense of the option (overwrite_null?), leave it empty by default, and possibly leave it undocumented for now because of its hard-to-explain limitations?

- Rename config option to overwrite_null
- Leave overwrite_null empty by default
- Handle more potentially null fields for both album and tracks
- Remove documentation and changelog entries for now
@djl
Copy link
Copy Markdown
Member Author

djl commented Jan 26, 2019

Updated the code to handle the track-level fields and inverted the logic as asked. Also removed the documentation and changelog entries for now.

And it looks like Travis is having a bad day.

@sampsyo
Copy link
Copy Markdown
Member

sampsyo commented Jan 26, 2019

Looking good; thanks! Travis seems like it's pointing out a very very nitpicky style complaint:
https://travis-ci.org/beetbox/beets/jobs/484712974#L1079

@djl
Copy link
Copy Markdown
Member Author

djl commented Jan 26, 2019

All green 👍

@sampsyo
Copy link
Copy Markdown
Member

sampsyo commented Jan 27, 2019

Awesome! This looks like it will be useful to build on, and it made the code for that function simpler. Thanks for your help with this!! ✨

@sampsyo sampsyo merged commit def5ff0 into master Jan 27, 2019
@djl djl deleted the no_clobber branch January 27, 2019 09:29
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.

2 participants