code: def test_discriminator():
      # Example adapted from
      # [Pydantic docs](https://pydantic-docs.helpmanual.io/usage/types/#discriminated-unions-aka-tagged-unions):
  
      class Cat(SQLModel):
          pet_type: Literal["cat"]
          meows: int
  
      class Dog(SQLModel):
          pet_type: Literal["dog"]
          barks: float
  
      class Lizard(SQLModel):
          pet_type: Literal["reptile", "lizard"]
          scales: bool
  
      class Model(SQLModel):
          pet: Union[Cat, Dog, Lizard] = Field(
              ..., discriminator="pet_type"
          )
          n: int
  
      Model(pet={"pet_type": "dog", "barks": 3.14}, n=1)  # type: ignore[arg-type]
  
      with pytest.raises(ValidationError):
          Model(pet={"pet_type": "dog"}, n=1)
  
file_path: sqlmodel/tests/test_pydantic/test_field.py
imports: from decimal import Decimal
  from typing import Optional, Union
  import pytest
  from pydantic import ValidationError
  from sqlmodel import Field, SQLModel
  from typing_extensions import Literal
label_desc: Use image node_id 2 for calling a global function with example usage: test_discriminator() without return types