Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model converter behavior change #2376

Closed
vaniakov opened this issue Mar 18, 2021 · 3 comments
Closed

Model converter behavior change #2376

vaniakov opened this issue Mar 18, 2021 · 3 comments

Comments

@vaniakov
Copy link

vaniakov commented Mar 18, 2021

Hi!
While updating peewee from 3.13.3 to 3.14.3 I noticed model converter behavior change.
If model has str method defined, it is used to represent this model's value in the expression instead of primary key:

import uuid
from peewee import *


db = SqliteDatabase(":memory:")


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


class User(BaseModel):
    id = CharField(max_length=255, primary_key=True)
    name = CharField(max_length=255)

    def __str__(self):
        return f"{self.name}"


if __name__ == "__main__":
    User.create_table()

    users = []
    for i in range(10):
        users.append(User.create(id=uuid.uuid4(), name=f"User_{i}"))

    query = User.filter(User.id << users)
    print(query.sql())
    print(list(query))

Output:

('SELECT "t1"."id", "t1"."name" FROM "user" AS "t1" WHERE ("t1"."id" IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?))', ['User_0', 'User_1', 'User_2', 'User_3', 'User_4', 'User_5', 'User_6', 'User_7', 'User_8', 'User_9'])
[]

The change was introduced in this commit: ebe3ad5

I'm wondering is this behavior is intentional.
Thanks.

@vaniakov vaniakov reopened this Mar 19, 2021
@coleifer
Copy link
Owner

Thanks for the succinct report and isolating the problematic changeset. No, this was a regression that I didn't foresee. I've patched this and will issue a new release.

@coleifer
Copy link
Owner

This is fixed and I've tagged a new version 3.14.4, which contains the fix and additional tests.

@vaniakov
Copy link
Author

@coleifer Thank you for such quick response and fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants