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

Avoid Pydantic serializer warnings #560

Open
Mini256 opened this issue Jan 3, 2025 · 2 comments
Open

Avoid Pydantic serializer warnings #560

Mini256 opened this issue Jan 3, 2025 · 2 comments
Assignees

Comments

@Mini256
Copy link
Member

Mini256 commented Jan 3, 2025

/usr/local/lib/python3.11/site-packages/pydantic/_internal/_std_types_schema.py:291: UserWarning: Pydantic serializer warnings:
  Expected `enum` but got `int` - serialized value may not be as expected
  Expected `enum` but got `int` - serialized value may not be as expected
  Expected `enum` but got `int` - serialized value may not be as expected
  Expected `enum` but got `int` - serialized value may not be as expected
  Expected `enum` but got `int` - serialized value may not be as expected
  Expected `enum` but got `int` - serialized value may not be as expected
  Expected `enum` but got `int` - serialized value may not be as expected
  Expected `enum` but got `int` - serialized value may not be as expected
  v = handler(item, index)
@sszgwdk
Copy link
Collaborator

sszgwdk commented Jan 15, 2025

Which interface call will trigger this warning?

@sszgwdk
Copy link
Collaborator

sszgwdk commented Jan 18, 2025

The root of this issue lies in the mismatch between how SQLAlchemy and Pydantic handle enum values:

  1. Pydantic expects to work with the ChatVisibility enum itself.
  2. SQLAlchemy stores the enum as an integer (SmallInteger) in the database.
  3. When fetching values from the database, SQLAlchemy provides raw integers (0 or 1), which leads to warnings during serialization because Pydantic requires the ChatVisibility enum type.

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