Issue: ArrayField: contains_any returning 'A||'
Author: havannavar
State: closed
Created: 2015-02-22 08:32:38

Here is my Model

class BlogPost(BaseModel):
    user = TextField()
    content = TextField()
    tags = ArrayField(TextField)

data in database is BlogPost(user='abc',content='awesome', tags=['foo', 'bar', 'baz'])"

and when i execute 
Blog.select().where(Blog.tags.contains_any('python', 'bar'))

I always get an Error 'A||'

Am i missing something here??


I'm not sure... the code is tested and here is a sample script that runs fine on my computer:

``` python
#!/usr/bin/env python

import logging

from peewee import *
from peewee import create_model_tables
from playhouse.postgres_ext import *


db = PostgresqlExtDatabase('peewee_test')

class BaseModel(Model):
    class Meta:
        database = db

class BlogPost(BaseModel):
    title = TextField()
    tags = ArrayField(TextField)


def main():
    db.create_tables([BlogPost], True)
    BlogPost.delete().execute()
    BlogPost.create(
        title='awesome',
        tags=['foo', 'bar', 'baz'])
    BlogPost.create(
        title='bad',
        tags=['foo', 'bax', 'baz'])
    for b in BlogPost.select().where(BlogPost.tags.contains_any('python', 'bar')):
        print b.title

if __name__ == '__main__':
    main()
```

Prints

```
awesome
```

You're using `playhouse.postgres_ext.PostgresqlExtDatabase`, right?


yeah thats the reason, i was using 

playhouse.pool.PooledPostgresqlDatabase my bad didn't check the what Postgres class it refers to 
now using 
playhouse.pool.PooledPostgresqlExtDatabase

Many thanks..


Charles,

when i enter query like the below,
BlogPost.select().where(BlogPost.tags.contains_any('bax', 'bar'))

I get only one result, instead it should be 2, i saw in peewee generated sql 

WHERE ("t1"."TAGS" && %s) LIMIT 1 [<playhouse.postgres_ext._Array object at 0x1128dbe10>]

what could be the reason?


Are you calling `.get()`, or why is there a `LIMIT 1` on the query?


```
class BlogPost(BaseModel):
    title = TextField()
    tags = ArrayField(TextField)
    name = TextField()

def main():
    db.create_tables([BlogPost], True)
    BlogPost.delete().execute()
    BlogPost.create(
         title='awesome',
        name='george',
         tags=['foo', 'bar', 'baz'])
     BlogPost.create(
    title='bad',
    name='george',
    tags=['foo', 'bax', 'baz'])
BlogPost.select().where(name='george' and BlogPost.tags.contains_any('python', 'bar'))
```

I m not calling .get(), i don't have an idea why there is LIMIT 1 on the query?

I just tried 

BlogPost.select().where(name='george' and BlogPost.tags.contains_any('bar'))

Still the same result


Bro, take like 2 seconds and see how to format the code in your comments.


`BlogPost.select().where(name='george' and BlogPost.tags.contains_any('python', 'bar'))`

That is invalid. You want instead:

``` python
BlogPost.select().where(
    (BlogPost.name == 'george') &
    (BlogPost.tags.contains_any('python', 'bar'))
```

Check the docs for more examples: http://docs.peewee-orm.com/en/latest/peewee/querying.html#query-operators


I did the format :+1: 

As i said earlier 

```
 BlogPost.select().where(BlogPost.tags.contains_any('bar')) 
```

Even for the above query able to retrieve only one result, it is not retrieving multiple


I'm not sure what's going on. This code works for me:

``` python
#!/usr/bin/env python

import logging

from peewee import *
from peewee import create_model_tables
from playhouse.postgres_ext import *


db = PostgresqlExtDatabase('peewee_test')

class BaseModel(Model):
    class Meta:
        database = db

class BlogPost(BaseModel):
    title = TextField()
    tags = ArrayField(TextField)


def main():
    db.create_tables([BlogPost], True)
    BlogPost.delete().execute()
    BlogPost.create(
        title='awesome',
        tags=['foo', 'bar', 'baz'])
    BlogPost.create(
        title='radical',
        tags=['python', 'foo', 'bla'])
    BlogPost.create(
        title='bad',
        tags=['foo', 'bax', 'baz'])
    q = BlogPost.select().where(BlogPost.tags.contains_any('python', 'bar'))
    print q
    for b in q:
        print b.title

if __name__ == '__main__':
    main()
```

Output:

```
<class '__main__.BlogPost'> SELECT "t1"."id", "t1"."title", "t1"."tags" FROM "blogpost" AS t1 WHERE ("t1"."tags" && %s) [<playhouse.postgres_ext._Array object at 0x7f547afbd310>]
awesome
radical
```


Wonder !!
I didn't found out the exact reason for the above issue, but after restarting my IDE and posgresql , everything starts working as expected, could be caching issues??

Thanks Charles once again !!
I may come up with more issues, as i m new to peewee and in hurry to release our product.