feldroy / feldroy/AirModel

Bug: `UUID` primary key fields create `INTEGER` columns instead of `UUID`

Open
#3 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## 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:
```python
from uuid import UUID
from airmodel import AirModel, AirField

class MyModel(AirModel):
id: UUID = AirField(primary_key=True)
name: str
```

2. Call `_column_defs()` to inspect the generated column definitions:
```python
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`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.