Issue: MySQL query working in 2.10.2 not working in 3.0.2
Author: J-Light
State: closed
Created: 2018-01-30 05:06:25

I am using a MySQL database and my application is producing errors when upgrading to 3.0.2. The documented changed for v3 does not indicate the source of the error. 

The following query is in 3.0.2 is
```
('SELECT  FROM `aos_products` AS `t1` WHERE ((`t1`.`aos_product_category_id` IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)) AND (`t1`.`id` = %s))', ['999f7d89-7d6a-13d0-4ba7-59fdb9e5b973', '9a088851-891a-257c-9ca2-59fdb9ab4e97', '9a771edd-a87b-08e5-a194-59fdb9c48633', '9a7cfe07-37b2-d6c7-3628-59fdb976cc9f', '9a827bb0-25ce-13e7-4c01-59fdb93a947b', '9a880187-460e-2982-1461-59fdb939ac0a', '9a92f875-1fde-5252-ffd1-59fdb9d0d497', '9a987012-454d-f8f0-818c-59fdb91f46ad', '9a9dfd80-4ed4-33bc-1662-59fdb9c9715b', '9aa3f3f4-0503-cb3e-5c74-59fdb9444991', '9aa9769d-a20f-5c39-16af-59fdb926c3e0', '9b481dcb-e8a3-0407-ab28-59fdb9bced65', '9b4da0c1-c8be-3061-75fc-59fdb9bbdb69', '9b532305-5654-0402-a612-59fdb95fdc75', '9b58b06f-add2-ec75-e601-59fdb9c6eeca', '9b5ece23-af3a-d3ab-1a36-59fdb9e30fa8', '9b645650-4077-e7b9-d702-59fdb99ea4a7', '9b69d753-bc39-1f0f-ba36-59fdb90a4aa1', '9b6f675a-2a76-f352-db75-59fdb9851747', '9b753dc2-e403-501f-618c-59fdb991e122', '9b7ae386-2714-9f52-020c-59fdb96c3ede', '9c124a19-2c9f-fc5b-3110-59fdb928d43f', '9c1817c2-b6e4-7796-3ef1-59fdb9ed3dc7', '9c1da5be-8bf9-fbe6-080f-59fdb9c1e7c1', '9c23273c-ec8e-b976-fea9-59fdb923768b', '9c28acbb-9208-8f6d-abea-59fdb9bd3178', '9c3ee8d2-6e4a-1e4b-aab3-59fdb9ef16bb', '855651d1-178e-39ba-3c7e-59fdba4a1972'])
```

This results in the following error:

```
*** peewee.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM `aos_products` AS `t1` WHERE ((`t1`.`aos_product_category_id` IN ('999f7d89' at line 1")
```

Downgrading to 2.10.2 the same query is;
```
('SELECT `t1`.`id`, `t1`.`aos_product_category_id`, `t1`.`assigned_user_id`, `t1`.`category`, `t1`.`contact_id`, `t1`.`cost`, `t1`.`cost_usdollar`, `t1`.`created_by`, `t1`.`currency_id`, `t1`.`date_entered`, `t1`.`date_modified`, `t1`.`deleted`, `t1`.`description`, `t1`.`maincode`, `t1`.`modified_user_id`, `t1`.`name`, `t1`.`part_number`, `t1`.`price`, `t1`.`price_usdollar`, `t1`.`product_image`, `t1`.`type`, `t1`.`url` FROM `aos_products` AS t1 WHERE ((`t1`.`aos_product_category_id` IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)) AND (`t1`.`id` = %s))', ['999f7d89-7d6a-13d0-4ba7-59fdb9e5b973', '9a088851-891a-257c-9ca2-59fdb9ab4e97', '9a771edd-a87b-08e5-a194-59fdb9c48633', '9a7cfe07-37b2-d6c7-3628-59fdb976cc9f', '9a827bb0-25ce-13e7-4c01-59fdb93a947b', '9a880187-460e-2982-1461-59fdb939ac0a', '9a92f875-1fde-5252-ffd1-59fdb9d0d497', '9a987012-454d-f8f0-818c-59fdb91f46ad', '9a9dfd80-4ed4-33bc-1662-59fdb9c9715b', '9aa3f3f4-0503-cb3e-5c74-59fdb9444991', '9aa9769d-a20f-5c39-16af-59fdb926c3e0', '9b481dcb-e8a3-0407-ab28-59fdb9bced65', '9b4da0c1-c8be-3061-75fc-59fdb9bbdb69', '9b532305-5654-0402-a612-59fdb95fdc75', '9b58b06f-add2-ec75-e601-59fdb9c6eeca', '9b5ece23-af3a-d3ab-1a36-59fdb9e30fa8', '9b645650-4077-e7b9-d702-59fdb99ea4a7', '9b69d753-bc39-1f0f-ba36-59fdb90a4aa1', '9b6f675a-2a76-f352-db75-59fdb9851747', '9b753dc2-e403-501f-618c-59fdb991e122', '9b7ae386-2714-9f52-020c-59fdb96c3ede', '9c124a19-2c9f-fc5b-3110-59fdb928d43f', '9c1817c2-b6e4-7796-3ef1-59fdb9ed3dc7', '9c1da5be-8bf9-fbe6-080f-59fdb9c1e7c1', '9c23273c-ec8e-b976-fea9-59fdb923768b', '9c28acbb-9208-8f6d-abea-59fdb9bd3178', '9c3ee8d2-6e4a-1e4b-aab3-59fdb9ef16bb', '855651d1-178e-39ba-3c7e-59fdba4a1972'])
```


Can you share the code for constructing the query? Specifically, what arguments are you passing to the `.select()` method?

@coleifer in both cases the querry is 

`temp_prods.select().where(mymodel.AosProducts.name==prd_name).get()`

where,
`temp_prods = database_products.select().where(database_products.aos_product_category << sub_cat)`

Ahh, thanks.

In that case, since you're not altering the columns being selected, you do not need the call to `select()` on `temp_prods`:

```python
temp_prods = database_products.select().where(database_products.aos_product_category << sub_cat)
the_obj = temp_prods.where(mymodel.AosProducts.name == prd_name).get()
```

When you are calling `select()` a 2nd time, it is clearing-out the initial (default) selection, which is to select all fields. Although this is a regression, I'm not too inclined to patch it since the behavior is only triggered by an unnecessary 2nd call to `select()`.

Well, I went ahead and fixed it :)