Why is db not associated with a value

This is the code for an inventory manager, I started the API, checked if it was up, than ran a test file. I have been geting internal server errors, it’s saying db is not associated with a value but it is.

from fastapi import FastAPI, HTTPException, Depends
from systemfiles import db, models, schemas

app = FastAPI()

# Dependency injection for database session
def get_db():
    db = db.SessionLocal()
    try:
        yield db
    finally:
        db.close()

@app.get("/products/", response_model=list[schemas.product])
async def get_products(db: db.SessionLocal = Depends(get_db)):
    products = db.query(models.Product).all()
    return products

@app.post("/products/", response_model=schemas.product, status_code=201)
async def create_product(product: schemas.ProductCreate, db: db.SessionLocal = Depends(get_db)):
    db_product = models.Product(**product.model_dump())
    db.add(db_product)
    db.commit()
    db.refresh(db_product)
    return db_product

@app.get("/products/{product_id}", response_model=schemas.product)
async def get_product(product_id: int, db: db.SessionLocal = Depends(get_db)):
    product = db.query(models.Product).filter(models.Product.id == product_id).first()
    if not product:
        raise HTTPException(status_code=404, detail="Product not found")
    return product

everything seems ok but i have been getting this traceback in the uvicorn terminal :

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesuvicornprotocolshttph11_impl.py", line 408, in run_asgi  
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesuvicornmiddlewareproxy_headers.py", line 84, in __call__  
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesfastapiapplications.py", line 1106, in __call__
    await super().__call__(scope, receive, send)
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesstarletteapplications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesstarlettemiddlewareerrors.py", line 184, in __call__      
    raise exc
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesstarlettemiddlewareerrors.py", line 162, in __call__      
    await self.app(scope, receive, _send)
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesstarlettemiddlewareexceptions.py", line 79, in __call__   
    raise exc
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesstarlettemiddlewareexceptions.py", line 68, in __call__   
    await self.app(scope, receive, sender)
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesfastapimiddlewareasyncexitstack.py", line 20, in __call__ 
    raise e
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesfastapimiddlewareasyncexitstack.py", line 17, in __call__ 
    await self.app(scope, receive, send)
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesstarletterouting.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesstarletterouting.py", line 276, in handle
    await self.app(scope, receive, send)
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesstarletterouting.py", line 66, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesfastapirouting.py", line 264, in app
    solved_result = await solve_dependencies(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesfastapidependenciesutils.py", line 595, in solve_dependencies
    solved = await solve_generator(
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesfastapidependenciesutils.py", line 520, in solve_generator
    return await stack.enter_async_context(cm)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libcontextlib.py", line 647, in enter_async_context
    result = await _enter(cm)
             ^^^^^^^^^^^^^^^^
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libcontextlib.py", line 204, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersRayaans LaptopAppDataLocalProgramsPythonPython312Libsite-packagesfastapiconcurrency.py", line 36, in contextmanager_in_threadpool
    raise e
UnboundLocalError: cannot access local variable 'db' where it is not associated with a value

heres the code inside systemfiles/db.py:

from sqlalchemy import create_engine, Column, Integer, String, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# Create the database engine
engine = create_engine("sqlite:///inventory.db")

# Create a SessionLocal class for creating database sessions
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

# Create a base class for declarative models
Base = declarative_base()

def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật