Description
When a model defines an ID field as a UUID with primary_key=True, the ORM incorrectly creates a BIGSERIAL (auto-incrementing integer) column instead of a UUID column.
Steps to Reproduce
- Define a model with a UUID primary key:
from uuid import UUID
from airmodel import AirModel, AirField
class MyModel(AirModel):
id: UUID = AirField(primary_key=True)
name: str
- Call
_column_defs() to inspect the generated column definitions:
cols = MyModel._column_defs()
print(cols[0])
# Expected: '"id" UUID PRIMARY KEY'
# Actual (before fix): '"id" BIGSERIAL PRIMARY KEY'
Expected Behavior
UUID primary key fields should create UUID PRIMARY KEY columns in PostgreSQL, not BIGSERIAL PRIMARY KEY columns.
Actual Behavior
UUID primary key fields are incorrectly mapped to BIGSERIAL columns, which are auto-incrementing integers.
Root Cause
The _column_defs() method in src/airmodel/main.py assumes all primary keys should be BIGSERIAL without checking the actual field type.
Environment
- OS: macOS 26.2 (Darwin 25.2.0)
- Python: 3.13.3
- AirModel: Latest main branch
Fix
The fix checks the primary key field's type and uses the appropriate PostgreSQL type:
int types → BIGSERIAL PRIMARY KEY
UUID types → UUID PRIMARY KEY
- Other types → appropriate type +
PRIMARY KEY
Description
When a model defines an ID field as a UUID with
primary_key=True, the ORM incorrectly creates a BIGSERIAL (auto-incrementing integer) column instead of a UUID column.Steps to Reproduce
_column_defs()to inspect the generated column definitions:Expected Behavior
UUID primary key fields should create
UUID PRIMARY KEYcolumns in PostgreSQL, notBIGSERIAL PRIMARY KEYcolumns.Actual Behavior
UUID primary key fields are incorrectly mapped to BIGSERIAL columns, which are auto-incrementing integers.
Root Cause
The
_column_defs()method insrc/airmodel/main.pyassumes all primary keys should be BIGSERIAL without checking the actual field type.Environment
Fix
The fix checks the primary key field's type and uses the appropriate PostgreSQL type:
inttypes →BIGSERIAL PRIMARY KEYUUIDtypes →UUID PRIMARY KEYPRIMARY KEY