title: How to partially update data with FastAPI and PyDantic BaseModel using PATCH
body: <p>I'd like to partly update database via PATCH method in FastAPI. I use Postgres as my database, Postman to test.</p>
  <p>I followed the example on FastAPI document, link: <a href="https://fastapi.tiangolo.com/tutorial/body-updates/#partial-updates-with-patch" rel="nofollow noreferrer">https://fastapi.tiangolo.com/tutorial/body-updates/#partial-updates-with-patch</a></p>
  <p>I use GET to fetch the original data in DB, copy the content to body raw json, then change the part where I need to update and choose PATCH, click send in Postman, an error occurs: <strong>main.Product() argument after ** must be a mapping, not Product</strong></p>
  <p>What is the right approach to PATCH data? I omitted the code to connect to Postgres using psycopg2</p>
  <pre><code>from fastapi import FastAPI, Response, status, HTTPException, Path
  from fastapi.encoders import jsonable_encoder
  from pydantic import BaseModel
  
  app = FastAPI()
  
  class Product(BaseModel):
      name: str
      price: float
      inventory: int
  
  @app.get(&quot;/posts/{id}&quot;)
  def get_a_post(id: int = Path(None, title='Prod ID')):
      cursor.execute('''SELECT * FROM public.products WHERE ID = %s''',(str(id),))
      post = cursor.fetchone()
      if not post:
          raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
                              detail=f&quot;product with id {id} was not found!&quot;)
      return post
  
  @app.patch(&quot;/posts/{id}&quot;, response_model=Product)
  def patch_posts(id: int, post: Product):
      stored_data = post
      stored_model = Product(**stored_data)
      update_data = post.dict(exclude_unset=True)
      updated_data = stored_model.copy(update=update_data)
      post = jsonable_encoder(updated_data)
      return{&quot;partially updated product&quot;: post}
  </code></pre>