-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try normalizing the dbcore String type #3774
Conversation
Strings were not being normalized, unlike some other types, leading to downstream problems like #3773.
That looks a lot like Lines 89 to 91 in 52ca0cb
should be adressed, right? Does anyone (in particular @geigerzaehler according to In fact, maybe |
Absolutely, yeah, that would be the thing to fix. Here's the context as best as I can remember. Before we added the type system, lots of parts of the codebase were very loosey-goosey about how they used various fields. This was a growing problem, of course, which is why we added the types in the first place. But we were nervous about all that existing code being that was so loosey-goosey about the types. The idea was to proceed in two phases:
You could imagine adding a third phase to this, as @wisp3rwind suggested: instead of silently converting things like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried to run the tests with the change mentioned in the TODO
note above. There's one test failure, namely test_format_flex_field_bytes
in test_dbcore
. The issue is that types.Default
then forces all flexattrs to unicode, but the test expects to be able to write utf8 bytes to the database. I'm pretty sure that forcing unicode here would break flexattr usage by some plugins. And since the database actually stores bytes rather than unicode objects (right?), it seems sensible to be able to write raw bytes.
So it might indeed by best to only coerce String
s to their model_type
, not all fields.
beets/dbcore/types.py
Outdated
@@ -207,6 +207,12 @@ class String(Type): | |||
sql = u'TEXT' | |||
query = query.SubstringQuery | |||
|
|||
def normalize(self, value): | |||
if value is None: | |||
return self.model_type() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be cleaner to return self.null
here (even though that is just self.model_type()
for String
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you're absolutely right about that.
Intriguing! Thanks for trying that out. Let's keep the dream alive—maybe we can work around that limitation by, for example, allowing fields without a declared type to remain dynamically typed and not coerced. But for now, we can make this more conservative change for strings only. |
This is an attempt to fix #3773 by more aggressively normalizing values for dbcore's
String
type.