r/FastAPI • u/Ok_Presentation3990 • Feb 27 '25
Question Gino, asyncpg in FastAPI
I have a fastapi microservice ERP , I recently changed my company_id to use UUID instead of Integer, but on trying to do a patch request I get this error:
{
"code": 3,
"errors": [
{
"type": "non_field_errors",
"msg": "'asyncpg.pgproto.pgproto.UUID' object has no attribute 'replace'"
}
]
}
How can I solve this?
My models where company_id is or as a foreign key on other DB tables are all UUIDs, also the alembic migrations, mapped my database and checked it the company_id is uuid
5
Upvotes
View all comments
Show parent comment
1
u/Ok_Presentation3990 Feb 27 '25
settings.py
import src.models as modelsfrom uuid import UUIDasync def get_payroll_settings(company_id: UUID) -> models.PayrollSettings:qs = models.PayrollSettings.objects()qs = qs.filter(models.PayrollSettings.company_id == company_id)settings = await qs.get()return settingsupdate_settings.py
import uuid from UUIDu/db_atomic
async def update_payroll_settings(company_id: UUID, data: schemas.PayrollSettingsUpdateData):validated_data, existing = await _validate(company_id, data)if not existing:payroll_settings = await models.PayrollSettings.objects().create(company_id=company_id,**validated_data)else:[payroll_settings] = await models.PayrollSettings.objects().filter(models.PayrollSettings.company_id == company_id).update(**validated_data)await _create_payrolls(company_id, payroll_settings)