-
-
Notifications
You must be signed in to change notification settings - Fork 117
Support JSON values returned from .convert() functions #495
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
Comments
This makes sense to me. There are other places in the codebase where JSON is automatically stringified: sqlite-utils/sqlite_utils/db.py Lines 2759 to 2766 in c7e4308
I don't see why the return value from a convert function shouldn't do the same thing. Since this will result in previous errors working, I don't think it warrants a major version bump either. |
There is a case where the function can return a dictionary at the moment: table.convert(
"title", lambda v: {"upper": v.upper(), "lower": v.lower()}, multi=True
) But I think this change is still compatible with that. if you don't use table.convert(
"title", lambda v: {"upper": {"str": v.upper()}, "lower": {"str": v.lower()}}, multi=True
) This would result in a |
I've decided not to explicitly document this, since it's consistent with how other parts of the library work already. |
When using the convert function on a JSON column, the result of the conversion function must be a string. If the return value is either a dict (object) or a list (array), the convert call will error out with an unhelpful user defined function exception.
It makes sense that since the original column value was a string and required conversion to data structures, the result should be converted back into a JSON string as well. However, other functions auto-convert to JSON string representation, so the fact that convert doesn't could be surprising.
At least the documentation should note this requirement, because the sqlite error messages won't readily reveal the issue.
Jf only sqlite's JSON column type meant something :)
The text was updated successfully, but these errors were encountered: