tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.38k stars 356 forks source link

fix `exclude_readonly` param not working in `pydantic_model_creator` #1594

Closed Abdeldjalil-H closed 2 months ago

Abdeldjalil-H commented 2 months ago

The exclude_readonly paramter in pydantic_model_creator is not working, i.e it is ignored. readOnly is deleted from fdesc["constraints"] so instead we read it from extra_json_schema.

Checklist:

abondar commented 2 months ago

Hi, thanks for PR! Could you please add some small test, that shows that changed behaviour now works?

coveralls commented 2 months ago

Pull Request Test Coverage Report for Build 8830975307

Details


Totals Coverage Status
Change from base Build 8820987871: 0.01%
Covered Lines: 5733
Relevant Lines: 6389

💛 - Coveralls
Abdeldjalil-H commented 2 months ago

I have added a test case @abondar.

abondar commented 2 months ago

Seems like that test passes also on previous version, that doesn't have fix

I assume it is because we already exclude id somewhere here https://github.com/tortoise/tortoise-orm/blob/develop/tortoise/contrib/pydantic/creator.py#L272

Did you originally face problem on some more complex case? Are you able to reproduce it using test models?

Abdeldjalil-H commented 2 months ago

Yes, I have faced the issue with some models that have created_at which is auto_now field. I have changed the test case to modified on Event model. By the way, this was working on previous version (with pydantic 1).