Skip to content
Discussion options

You must be logged in to vote

.as_string() is the right call here, not a workaround. It's the documented SQLAlchemy way and your original attempt is doing something subtly different than you'd expect.

When you write Foo.meta["hello"], the indexed access gives you back a value that's still typed as JSON, not as text. So Foo.meta["hello"] == "world" is a JSON-to-JSON comparison. On SQLite that renders as JSON_QUOTE(JSON_EXTRACT(meta, '$."hello"')), and JSON_QUOTE wraps the value in quotes, so you're really comparing the string "world" (quotes included) against your bare 'world'. They never match, which is why you get None.

.as_string() tells SQLAlchemy to pull the element out as text instead of JSON, so it drops the JSO…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants