title: Best practice to set default variable for pydantic field at runtime
body: <p>I have a pydantic model for request like below,</p>
  <pre><code>from pydantic import BaseModel, Field
  from typing import List, ClassVar
  from fastapi import FastAPI
  
  
  app = FastAPI()
  
  
  class myRequestModel(BaseModel):
     items: List[str] = Field(..., example=['a','b'])
     n: int = Field(100, example=50, gt=0)
  
  
  @app.post(&quot;/test&quot;)
  def test_func(args: myRequestModel):
     dynamic_threshold = my_func(...)     # let say dynamic_threshold is determined at runtime
     
     if args.n &lt; dynamic_threshold:
        args.n = 100                      # I want to assign args.n only when it is under dynamic_threshold
  </code></pre>
  <p>When users do not give <code>n</code>, it is automatically set to 100 which is default value through <code>Field</code> attribute.</p>
  <p>If users give <code>n</code> less than <code>dynamic_threshold</code>, it needs to be set to default value.</p>
  <p>In order to achieve this, I tried to add <code>_default_n</code> using <code>typing.ClassVar</code>. See below,</p>
  <pre><code>class myRequestModel(BaseModel):
     _default_n: ClassVar[int] = 100
     n: int = Field(_default_n, example=100, gt=0)
     ...
  
     class Config:
        underscore_attrs_are_private = True
  
  
  @app.post(&quot;/test&quot;)
  def test_func(args: myRequestModel):
     ...
     
     if args.n &lt; dynamic_threshold:
        args.n = args._default_n      &lt;-- Here, I get a warning 'Access to a protected member _default_n of a class
  </code></pre>
  <p>This works, but I don't think this is not a right way for warning..</p>
  <p>What is the appropriate way to make default value that can be used at runtime?</p>