[Python] SQLModel and emails

Discussão em 'Python' iniciado por Stack, Agosto 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently working on an api using fastapi and sqlmodel. I'm new to these two and I might have missed something.

    I have a user model with an e-mail field. So no email outside my organization is inserted inside the database I have set the email field as such:

    class User(SQLModel, table=True):
    __tablename__ = 'users'
    id: UUID = Field(default_factory=uuid4, primary_key=True)
    username: str = Field(index=True, max_length=30)
    email: str = Field(max_length=50, schema_extra={'pattern': r'^email pattern$'})


    I've read in some github issues that the regex parameter is not working properlly with pydantic and the supposed way to do this is by using the schema_extra parameter.

    Unfortunately when I try to insert an e-mail that does not match the pattern it still does get inserted into the database. Am I missing something here? Have anyone encountered this same issue?

    Continue reading...

Compartilhe esta Página