MongodbSerializer does not serialize isNotEmpty() properly #1264

Closed
johnktims opened this Issue Mar 17, 2015 · 16 comments

Projects

None yet

3 participants

@johnktims
Member

Original link: http://stackoverflow.com/questions/29104204/querydsl-isnotempty-expression-failing

There appears to be a serialization error in MongodbSerializer for

BooleanExpression expr = qa.matches.isNotEmpty();
Iterable<A> result = aRepo.findAll(expr);

assertThat(result, is(not((emptyIterable()))));

MongodbSerializer is spitting out

{ "$or" : { "$not" : [ { "matches" : [ ]} , { "matches" : { "$exists" : false}}]}}

which fails when I paste it into mongo.

> db.a.find({ "$or" : { "$not" : [ { "matches" : [ ]} , { "matches" : { "$exists" : false}}]}})
Error: error: {
    "$err" : "Can't canonicalize query: BadValue $or needs an array",
    "code" : 17287
}
> 

I rewrote the query as

> db.a.find({ "$or" : [ { "matches" : {$ne: [ ]}}, { "matches" : { "$exists" : false}}]}).pretty()
{
    "_id" : "a1",
    "_class" : "querydsldemo.A",
    "matches" : [
        {
            "_id" : ObjectId("55088ec4e4b0b6e56e76b1d6"),
            "name" : "b1"
        },
        {
            "_id" : ObjectId("55088ec4e4b0b6e56e76b1d7"),
            "name" : "b2"
        }
    ]
}
{ "_id" : "a3", "_class" : "querydsldemo.A" }

and then further simplified it as

> db.a.find({ "matches" : {$ne: [ ]}}).pretty()
{
    "_id" : "a1",
    "_class" : "querydsldemo.A",
    "matches" : [
        {
            "_id" : ObjectId("55088ec4e4b0b6e56e76b1d6"),
            "name" : "b1"
        },
        {
            "_id" : ObjectId("55088ec4e4b0b6e56e76b1d7"),
            "name" : "b2"
        }
    ]
}
{ "_id" : "a3", "_class" : "querydsldemo.A" }
> 

but I don't know if that's robust enough.

@timowest
Member

The negation seems to break, you can look at the handling of Ops.COL_IS_EMPTY and Ops.NOT.

@Shredder121
Member

It isn't really the negation, but the passing of an object to $or instead of elements. ('{ }' vs '[ ]') that breaks.

@timowest
Member

Yes, but I believe it is the negation processing that breaks it. The isempty logic looks ok.

@Shredder121
Member

Ah in that sense I agree.

@timowest timowest added the bug label Mar 18, 2015
@johnktims
Member

I did switch the expression to use isEmpty and that appeared to work properly (although obviously the opposite of what the user wants) so I think you're right, @timowest .

@timowest
Member

Is someone already working on this? Otherwise I can give it a try.

@johnktims
Member

I'm working on it now, but I'm not sure of the best way to fix this. The syntax for $not is making it difficult for me to fix. I haven't used mongodb a whole lot yet, so that might be the issue. :)

@Shredder121
Member

I am not, I only debugged it, but didn't yet solve it.

@timowest
Member

@johnktims Ok, let me know if you have some questions.

@johnktims
Member

Should every ticket be assigned to a milestone so that it isn't forgotten in the changelog?

@timowest
Member

Yes.

@johnktims johnktims added this to the 3.6.3 milestone Mar 18, 2015
@timowest timowest closed this in #1268 Mar 25, 2015
@Shredder121
Member

If we want it to appear in 3.6.3, I think we'll have to backport it.

@timowest
Member

Yes, I can do it, if @johnktims doesn't beat me at it.

@johnktims
Member

I was planning to backport it this morning. Have you started it?

@timowest
Member

No, haven't started yet. Feel free to do it, if you have time.

@johnktims
Member

Cool. I'll handle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment