You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I'm working back on this issue.
There is something I have trouble to figure out regarding the Comparator class combined with TypeDecorator that looks similar to #3859.
Even with a postgresql engine, the Comparator class in use seems to be the one from the base JSON. Calling the astext property raise an AttritubeError.
with_variant refers to the type object that takes place when the statement is passed to the compiler for conversion to SQL as well as when the compiled object is executed, where it is used to handle bound parameters and result values. However it cannot be used to impact the in-python Comparator behavior because the statement object is agnostic of any dialect at that point. that is, with_variant has no way to know that when you call column.astext it should be reaching into the "postgresql" variant. so with_variant cant be used in this way.
this should not be "astext" - the issue as shown in #4969 is that our use of JSON_QUOTE for sqlite is broken, as we don't correctly compare json to json in any case with that (note JSON_QUOTE uses no whitespace), we don't correclty compare booleans, so string/int/numeric just happen to work with that awkward "CAST" recipe but this is foolish. there shouldn't need to be a cast. the left side of a comparison should have dialect-specific ways of extracting the known JSON types out, and then there should be directives so that this can be supplied, like table.c.col['somekey'].to_boolean, to_string, to_int, to_numeric, to_json. then perhaps we can automatically derive these when used in a comparison, but that's optional.
Activity
sqlalchemy-bot commentedon Aug 1, 2018
Michael Bayer (@zzzeek) wrote:
can be pushed up if I can get development help
sqlalchemy-bot commentedon Aug 1, 2018
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Aug 1, 2018
Changes by Michael Bayer (@zzzeek):
Nutigoodpipes commentedon May 13, 2019
Hello, I'm working back on this issue.
There is something I have trouble to figure out regarding the
Comparatorclass combined withTypeDecoratorthat looks similar to #3859.Concretely, when I define :
Even with a postgresql engine, the
Comparatorclass in use seems to be the one from the base JSON. Calling theastextproperty raise anAttritubeError.Do you have pointers of where I should look at ?
zzzeek commentedon May 13, 2019
with_variant refers to the type object that takes place when the statement is passed to the compiler for conversion to SQL as well as when the compiled object is executed, where it is used to handle bound parameters and result values. However it cannot be used to impact the in-python Comparator behavior because the statement object is agnostic of any dialect at that point. that is, with_variant has no way to know that when you call
column.astextit should be reaching into the "postgresql" variant. so with_variant cant be used in this way.zzzeek commentedon Nov 7, 2019
this should not be "astext" - the issue as shown in #4969 is that our use of JSON_QUOTE for sqlite is broken, as we don't correctly compare json to json in any case with that (note JSON_QUOTE uses no whitespace), we don't correclty compare booleans, so string/int/numeric just happen to work with that awkward "CAST" recipe but this is foolish. there shouldn't need to be a cast. the left side of a comparison should have dialect-specific ways of extracting the known JSON types out, and then there should be directives so that this can be supplied, like table.c.col['somekey'].to_boolean, to_string, to_int, to_numeric, to_json. then perhaps we can automatically derive these when used in a comparison, but that's optional.
sqla-tester commentedon Nov 7, 2019
Mike Bayer has proposed a fix for this issue in the master branch:
Add type accessors for JSON indexed/pathed element access https://gerrit.sqlalchemy.org/1560
sqla-tester commentedon Nov 10, 2019
Mike Bayer has proposed a fix for this issue in the rel_1_3 branch:
Add type accessors for JSON indexed/pathed element access https://gerrit.sqlalchemy.org/1572
Add type accessors for JSON indexed/pathed element access
Add type accessors for JSON indexed/pathed element access