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

Enums not quoted (bug of pypika-torotise) #1774

Closed
waketzheng opened this issue Nov 17, 2024 · 0 comments · Fixed by #1776
Closed

Enums not quoted (bug of pypika-torotise) #1774

waketzheng opened this issue Nov 17, 2024 · 0 comments · Fixed by #1776

Comments

@waketzheng
Copy link
Contributor

Describe the bug
Reported here: tortoise/pypika-tortoise#7

To Reproduce

from tortoise import Model, fields, run_async
from tortoise.contrib.test import init_memory_sqlite
from tortoise.fields.base import StrEnum


class MyModel(Model):
    id = fields.IntField(pk=True)
    name = fields.TextField()


class MyEnum(StrEnum):
    A = "a"


@init_memory_sqlite
async def do():
    await MyModel.create(name="a")
    qs = MyModel.filter(name=MyEnum.A)
    qs._make_query()
    print(qs.query)
    # expected   SELECT "id","name" FROM "mymodel" WHERE "name"='a'
    # actual     SELECT "id","name" FROM "mymodel" WHERE "name"=a
    print(await MyModel.filter(name=MyEnum.A).exists())
    # expected True
    # actual raises tortoise.exceptions.OperationalError: no such column: a


run_async(do())

Expected behavior
Support filter by enum

Additional context
Will be fixed after this PR(tortoise/pypika-tortoise#10) merged.

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

Successfully merging a pull request may close this issue.

1 participant