You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by Rahul Goswami <ra...@gmail.com> on 2022/08/28 02:47:08 UTC

Issue with Atomic update on boolean fields in Solr 8.11

Hi,
I am running Solr 8.11. As per the Solr documentation, any value starting
with "1","t" or "T" for a boolean field is interpreted as true.

https://solr.apache.org/guide/8_11/field-types-included-with-solr.html#recommended-field-types

However, I hit a potential Solr bug where if the String value  "1","t" or
"T"  is passed in an atomic update, it is treated as false.

//Eg:Below document is indexed first => query returns "inStock" as true (as
expected)
{
"id":"test",
"inStock":"true"
}

//Follow above update with below atomic update and commit. => inStock
becomes false in query result
{
"id":"test",
"inStock":{"set":"1"}
}

This doesn't happen though if value "1" is passed in a regular update.
Eg:Below update reflects the value of inStock as true when queried.
{
"id":"test",
"inStock":"1"
}

I tried to look for any existing JIRAs for this issue but couldn't find
one. So I wanted to float it in the community before creating one to avoid
possible duplicate tickets. Please let me know if I should create one.

Also, I identified the bug and would like to submit a PR.

Thanks,
Rahul

Re: Issue with Atomic update on boolean fields in Solr 8.11

Posted by Rahul Goswami <ra...@gmail.com>.
Created the below JIRA for the issue.
https://issues.apache.org/jira/browse/SOLR-16360

-Rahul

On Mon, Aug 29, 2022 at 11:29 AM Rahul Goswami <ra...@gmail.com>
wrote:

> Dmitri,
> I see this issue even when the document is an XML. I would like to note
> that clients send data inside CDATA ( [CDATA[my data]] ) in case any of the
> fields have XML strings as the value itself and want to avoid having those
> interpreted as XML markup.
>
> I agree with you in that I too wish Solr would have never gotten into the
> "1"-"t"-"T" business and maybe enforced strict values like "true" and
> "false". But as of now where we stand, this is a clear breakage. I will
> create a JIRA soon. Happy to take this one up and submit a PR.
>
> -Rahul
>
> On Sun, Aug 28, 2022 at 8:01 PM dmitri maziuk <dm...@gmail.com>
> wrote:
>
>> On 2022-08-28 5:36 PM, Rahul Goswami wrote:
>> > Hi Dmitri,
>> > I am not sure if I understand your second comment. Can you please
>> elaborate?
>>
>> Try doing it in XML instead of JSON. JSON has data types encoded in the
>> syntax and if it were me, I'd take those over the 't'-'1'-'F' guesswork.
>>
>> My $.02 is Solr shouldn't have been doing what TFM says in the first
>> place. Among other reasons, because once you have a managed schema and
>> "Field value class guessing", you have a chicken-and-egg problem.
>>
>> Or at least that behaviour should be limited to XML input and clearly
>> documented as such, with the caveat that if the field wasn't previously
>> defined, your result may be anything.
>>
>> Dima
>>
>>

Re: Issue with Atomic update on boolean fields in Solr 8.11

Posted by Rahul Goswami <ra...@gmail.com>.
Dmitri,
I see this issue even when the document is an XML. I would like to note
that clients send data inside CDATA ( [CDATA[my data]] ) in case any of the
fields have XML strings as the value itself and want to avoid having those
interpreted as XML markup.

I agree with you in that I too wish Solr would have never gotten into the
"1"-"t"-"T" business and maybe enforced strict values like "true" and
"false". But as of now where we stand, this is a clear breakage. I will
create a JIRA soon. Happy to take this one up and submit a PR.

-Rahul

On Sun, Aug 28, 2022 at 8:01 PM dmitri maziuk <dm...@gmail.com>
wrote:

> On 2022-08-28 5:36 PM, Rahul Goswami wrote:
> > Hi Dmitri,
> > I am not sure if I understand your second comment. Can you please
> elaborate?
>
> Try doing it in XML instead of JSON. JSON has data types encoded in the
> syntax and if it were me, I'd take those over the 't'-'1'-'F' guesswork.
>
> My $.02 is Solr shouldn't have been doing what TFM says in the first
> place. Among other reasons, because once you have a managed schema and
> "Field value class guessing", you have a chicken-and-egg problem.
>
> Or at least that behaviour should be limited to XML input and clearly
> documented as such, with the caveat that if the field wasn't previously
> defined, your result may be anything.
>
> Dima
>
>

Re: Issue with Atomic update on boolean fields in Solr 8.11

Posted by dmitri maziuk <dm...@gmail.com>.
On 2022-08-28 5:36 PM, Rahul Goswami wrote:
> Hi Dmitri,
> I am not sure if I understand your second comment. Can you please elaborate?

Try doing it in XML instead of JSON. JSON has data types encoded in the 
syntax and if it were me, I'd take those over the 't'-'1'-'F' guesswork.

My $.02 is Solr shouldn't have been doing what TFM says in the first 
place. Among other reasons, because once you have a managed schema and 
"Field value class guessing", you have a chicken-and-egg problem.

Or at least that behaviour should be limited to XML input and clearly 
documented as such, with the caveat that if the field wasn't previously 
defined, your result may be anything.

Dima


Re: Issue with Atomic update on boolean fields in Solr 8.11

Posted by Rahul Goswami <ra...@gmail.com>.
Hi Dmitri,
I am not sure if I understand your second comment. Can you please elaborate?

I am guessing your first comment is hinting at the value “1” being in
String context and hence should be interpreted as false(?) But that would
be inconsistent with the documentation and behavior until Solr7.x where it
was interpreted as true.

As per 8.x documentation:
“ Values of 1, t, or T in the first character are interpreted as true. Any
other values in the first character are interpreted as false.”

So technically even “1blah” should be interpreted as true, and in fact up
until 7.x, it is. Many clients send value 1 for some of the boolean fields
and the behavior in 8.x breaks backward compatibility (in a possibly
critical way. Saying “no” when you mean “yes” can have disastrous
consequences).

-Rahul


On Sun, Aug 28, 2022 at 12:33 PM dmitri maziuk <dm...@gmail.com>
wrote:

> On 2022-08-27 9:47 PM, Rahul Goswami wrote:
>
> > However, I hit a potential Solr bug where if the String value  "1","t" or
> > "T"  is passed in an atomic update, it is treated as false.
>
> Why would one want to interpret 1 as true in non-boolean context? (hint,
> hint)
>
> > This doesn't happen though if value "1" is passed in a regular update.
> > Eg:Below update reflects the value of inStock as true when queried.
> > {
> > "id":"test",
> > "inStock":"1"
> > }
>
> The bug is, I have 1 in stock. Not 2, not "true", just 1.
>
> Dima
>
>
>

Re: Issue with Atomic update on boolean fields in Solr 8.11

Posted by dmitri maziuk <dm...@gmail.com>.
On 2022-08-27 9:47 PM, Rahul Goswami wrote:

> However, I hit a potential Solr bug where if the String value  "1","t" or
> "T"  is passed in an atomic update, it is treated as false.

Why would one want to interpret 1 as true in non-boolean context? (hint, 
hint)

> This doesn't happen though if value "1" is passed in a regular update.
> Eg:Below update reflects the value of inStock as true when queried.
> {
> "id":"test",
> "inStock":"1"
> }

The bug is, I have 1 in stock. Not 2, not "true", just 1.

Dima