Fast API getting an error while post api in my bills model

Question:

So, i am using fast api and I am trying to add added_on in my taxbill schema here is my bill model

class TaxBillModel(Base):
__tablename__ = "taxbill"

id = Column(Integer, primary_key=True, index=True)
bill_no = Column(Integer, index=True)
amount = Column(Integer, nullable=False)
about = Column(String(50), nullable=True)
added_on = Column(DateTime)
modified_on = Column(DateTime)
user_id = Column(Integer, ForeignKey("users.id", ondelete='CASCADE'))

user = relationship("User", back_populates="taxbills")

and here is my bill schemas

class BillCreate(BillBase):
added_no: datetime = datetime.now()

# class Config:
#     validate_assignment = True

@root_validator
def number_validator(cls, values):
    values["added_no"] = datetime.now()
    return values

so when i am trying to make a post request it shows an error

TypeError: ‘added_no’ is an invalid keyword argument for TaxBillModel

and when i am printing my request data

@router.post('/{user_id}/taxbill/', 
            response_model=schemas.ShowBill, 
            status_code=status.HTTP_201_CREATED)
def create_tax_bill(user_id: int, request: schemas.BillCreate, db: Session = Depends(get_db)):
print(request.dict(), "====")
tax_bill = bill_model.TaxBillModel(**request.dict(), user_id=user_id)
db.add(tax_bill)
db.commit()
db.refresh(tax_bill)
return tax_bill

{‘bill_no’: 123, ‘amount’: 1212, ‘about’: ‘asdasda’, ‘added_no’: datetime.datetime(2023, 2, 10, 12, 10, 16, 432147)} ====

I am getting my added_on data in request data then why I am getting this error ??

Asked By: mdhv_kothari

||

Answers:

Your error suggests there is no added_no keyword.

TypeError: ‘added_no’ is an invalid keyword argument for TaxBillModel.

In fact, the field is added_on (no -> on) in TaxBillModel class.

{'bill_no': 123, 'amount': 1212, 'about': 'asdasda', 'added_no': datetime.datetime(2023, 2, 10, 12, 10, 16, 432147)}
#                                              ERROR HERE --^
Answered By: Corralien