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 |
wisp3rwind
left a comment
There was a problem hiding this comment.
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 Strings to their model_type, not all fields.
|
|
||
| def normalize(self, value): | ||
| if value is None: | ||
| return self.model_type() |
There was a problem hiding this comment.
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.
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
Stringtype.