Issue: Behavior of << differs from .in_() method for 2+ item lists
Author: chrisinmtown
State: closed
Created: 2015-08-14 15:31:41

I have a query that checks whether a 1-character column value is a member of a 4-element list.  If I write the query in Peewee using the << operator it works fine (I'm using constants):

```
           & (Doc2.doctype << [Doc2.DOCTYPE_A, Doc2.DOCTYPE_B, Doc2.DOCTYPE_C, Doc2.DOCTYPE_D])
```

However if I write the query using the .in_() method:

```
            & (Doc2.doctype.in_([Doc2.DOCTYPE_A, Doc2.DOCTYPE_B, Doc2.DOCTYPE_C, Doc2.DOCTYPE_D]))
```

It blows up with internal error 'Operand should contain 1 column(s)'. 

I found that << is equivalent to .in() if the list has exactly 1 item, but differs when the list has 2+ items.  In other words, this works:

```
            & (Doc2.doctype.in_([Doc2.DOCTYPE_A]))
```

Please see below. Thanks for listening
## 

Traceback (most recent call last):
 ... (name of my file omitted)
    for doc_row in doc_and_path_query:
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2514, in **iter**
    return iter(self.execute())
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2507, in execute
    self._qr = ResultWrapper(model_class, self._execute(), query_meta)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2203, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2833, in execute_sql
    self.commit()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2688, in __exit__
    reraise(new_type, new_type(*exc_value.args), traceback)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2825, in execute_sql
    cursor.execute(sql, params or ())
  File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 135, in execute
    result = self._query(query)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 274, in _query
    conn.query(q)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 714, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 865, in _read_query_result
    result.read()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1062, in read
    first_packet = self.connection._read_packet()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 830, in _read_packet
    packet.check_error()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 348, in check_error
    raise_mysql_exception(self._data)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 116, in raise_mysql_exception
    _check_mysql_exception(errinfo)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 112, in _check_mysql_exception
    raise InternalError(errno, errorvalue)
peewee.InternalError: (1241, u'Operand should contain 1 column(s)')


Weird, thanks for reporting.


Are you using an older version of peewee? I think the issue was that in older versions there was a bug where `in_()` took `*args` rather than a single list.

The bug was fixed in fcfd914f, part of the 2.5.1 release.


Omitted the version in my initial report, sorry, I was using 2.4.5.  I upgraded to 2.6.3 and the problem is gone.  Thanks for the very quick response.