tortoise / tortoise-orm

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

Primary key field should not be nullable #1778

Closed LanceMoe closed 6 days ago

LanceMoe commented 1 week ago

Primary key field should not be nullable

Description

If a value is a primary key, it should not be optional(nullable). For example, there is a Model called Foo, whose primary key is a UUIDField called id. Submitting a form using FooIn will use exclude_readonly=True, so the id field will not be included. And for output FooOut id cannot be nullable because it is the primary key. This PR fixes this problem.

Before: image

After: image

Motivation and Context

My projects use OpenAPI documentation auto-generated as a TypeScript client. It helps a lot to annotate the types correctly.

How Has This Been Tested?

This is a minor change, and it passes all existing tests. I tested it in a few of my live projects and it works fine.

Checklist:

coveralls commented 1 week ago

Pull Request Test Coverage Report for Build 11903355177

Details


Totals Coverage Status
Change from base Build 11887821450: 0.001%
Covered Lines: 6224
Relevant Lines: 6857

💛 - Coveralls