You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
When primary key is i.e. String, model instance returned from model.object.create has primary key as sequential integer. Once instance is fetched again, primary key is as expected - type and value wise.
Postgres behaviour is similar. Returned instance primary key in this case is actually None. Same for UUID type. Once fetched again, everything is as expected.
Could be that problem originates from databases library or incorrect usage of it.
Two copy/paste tests.
import random
import databases
import pytest
import sqlalchemy
import orm
from tests.settings import DATABASE_URL
from tests.test_columns import async_adapter
database = databases.Database(DATABASE_URL, force_rollback=True)
metadata = sqlalchemy.MetaData()
def key():
return "".join(random.choice("abcdefgh123456") for _ in range(8))
class Model(orm.Model):
__tablename__ = "model"
__metadata__ = metadata
__database__ = database
id = orm.String(primary_key=True, default=key, max_length=8)
name = orm.String(max_length=32)
@pytest.fixture(autouse=True, scope="function")
def create_test_database():
engine = sqlalchemy.create_engine(DATABASE_URL)
metadata.create_all(engine)
yield
metadata.drop_all(engine)
@async_adapter
async def test_pk_1():
model = await Model.objects.create(name="NAME")
assert isinstance(model.id, str)
@async_adapter
async def test_pk_2():
model = await Model.objects.create(name="NAME")
assert await Model.objects.all() == [model]