Skip to content

Bug: UUID primary key fields create INTEGER columns instead of UUID #3

@roselleebarle04

Description

@roselleebarle04

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

  1. 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
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions