Skip to content

SQLModel Field example param not working like Pydantic Field example paramΒ #456

@305jthompson

Description

@305jthompson

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options πŸ‘†

Example Code

Example #1 (This does not work)

from uuid import uuid4, UUID
from sqlmodel import SQLModel, Field as SQLModelField

class Address(AddressBase, table=True):
    id: UUID = SQLModelField(default_factory=uuid4, primary_key=True, index=True, nullable=False)
    zip: str = SQLModelField(example="12345")


Example #2 (This works)

from uuid import uuid4, UUID
from sqlmodel import SQLModel, Field as SQLModelField
from pydantic import Field as PydanticField

class Address(AddressBase, table=True):
    id: UUID = 
from sqlmodel import SQLModel, Field as SQLModelField(default_factory=uuid4, primary_key=True, index=True, nullable=False)
    zip: str = PydanticField(example="12345")

Description

I am trying to set an example on the model variable 'zip' so that it shows up as '12345' in the example values section on a route in the docs page.

This is what it looks like without adding the example

{
  "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "zip": "string"
}

This is what it looks like using the Pydantic Field value

{
  "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "zip": "12345"
}

When using SQLModel's 'Field' the example param returns the following error:

TypeError: Field() got an unexpected keyword argument 'example'

I'm not sure if this is the intended functionality for SQLModel's 'Field' or if this should work.

What is the preferred way of setting the schema_example variable with SQLModel?

Operating System

Linux

Operating System Details

No response

SQLModel Version

0.0.8

Python Version

Python 3.10.6

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions