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

Int enum is not passed as int #1385

Open
failable opened this issue Jul 19, 2024 · 0 comments
Open

Int enum is not passed as int #1385

failable opened this issue Jul 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@failable
Copy link

failable commented Jul 19, 2024

Describe the bug

The below code is modified from here. The translated query is

SELECT artists_v20.id AS id, artists_v20.name AS name, artists_v20.country AS country 
FROM artists_v20 
WHERE artists_v20.name = 'Jane Doe' AND artists_v20.country = 'UK' ORDER BY artists_v20.id 

The int num is not passed as int

import asyncio
import os
from enum import Enum

import databases
import ormar
import sqlalchemy

database_url = os.environ["DATABASE_URL"]

database = databases.Database(url=database_url)
metadata = sqlalchemy.MetaData()


class Country(int, Enum):
    UK = 1
    US = 2
    VIETNAM = 3
    COLOMBIA = 4


class ArtistV20(ormar.Model):
    ormar_config = ormar.OrmarConfig(
        database=database,
        metadata=metadata,
        tablename="artists_v20",
    )

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100)
    country: Country = ormar.Enum(enum_class=Country)


async def main():
    if not database.is_connected:
        await database.connect()

    engine = sqlalchemy.create_engine(database_url)
    metadata.create_all(engine)

    await ArtistV20.objects.all(name="Jane Doe", country=Country.UK)

    if database.is_connected:
        await database.disconnect()


if __name__ == "__main__":
    asyncio.run(main())

Expected behavior
The country column has int type in the database, so I expect the query will using int value 1 instead of 'UK'.

Versions (please complete the following information):

  • Database backend used: mysql Ver 8.3.0 for macos14.2 on x86_64 (Homebrew)
  • Python version: 3.10.11
  • ormar version: ormar==0.20.1
  • pydantic version: pydantic==2.5.3
@failable failable added the bug Something isn't working label Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant