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 }}
Repository navigation
Misbehaving model save() when names are too long #2018
Describe the bug
Model save() is not working when the model name and field name is too long and select_related is used.
To Reproduce
Tortoise ORM version: 0.25.1
Creating the test models:
from tortoise.models import Model
from tortoise import fields
class TUser(Model):
id = fields.UUIDField(primary_key=True)
name = fields.CharField(max_length=100)
user_information: fields.ReverseRelation["models.VeryLongNameForTestingPurposesOnlyUserInfo"]
short_user_info: fields.ReverseRelation["models.ShortUserInfo"]
class VeryLongNameForTestingPurposesOnlyUserInfo(Model):
id = fields.UUIDField(primary_key=True)
user: fields.OneToOneNullableRelation[TUser] = fields.OneToOneField(
model_name="models.TUser",
to_field="id",
related_name="user_information"
)
not_too_long_user_age = fields.IntField()
class ShortUserInfo(Model):
id = fields.UUIDField(primary_key=True)
user: fields.OneToOneNullableRelation[TUser] = fields.OneToOneField(
model_name="models.TUser",
to_field="id",
related_name="short_user_info"
)
age = fields.IntField()
Reproducing the issue:
print("Creating user and user info")
user = await TUser.create(name="Test User")
user_info = await VeryLongNameForTestingPurposesOnlyUserInfo.create(
user_id=user.id,
not_too_long_user_age=30,
)
short_info = await ShortUserInfo.create(
user_id=user.id,
age=30,
)
print("Working")
user = await TUser.filter(name="Test User").select_related("short_user_info").first()
user_info = user.short_user_info
user_info.age = 31
await user_info.save()
print("Not Working")
user = await TUser.filter(name="Test User").select_related("user_information").first()
user_info = user.user_information
user_info.not_too_long_user_age = 32
await user_info.save(
# update_fields=["not_too_long_user_age"]
)
This will raise:
IncompleteInstanceError: VeryLongNameForTestingPurposesOnlyUserInfo is a partial model, can only be saved with the relevant update_field provided
(Saving with update_fields works.)
Expected behavior
Saving with select_related should work regardless of the model name length.
I can confirm I managed to reproduce it with Postgres. I'm not familiar with the internals of Tortoise, but it seems this PR changed the behavior, specifically around this area:
Activity
waketzheng commentedon Nov 22, 2025
Can't reproduce with the following code:
rgabor-dev commentedon Nov 24, 2025
Hey @waketzheng, thanks for looking at it. It is happening when using a Postgres database. Probably because of the 64 char hard limit: https://www.postgresql.org/docs/current/runtime-config-preset.html#GUC-MAX-IDENTIFIER-LENGTH
seladb commentedon Mar 11, 2026
I can confirm I managed to reproduce it with Postgres. I'm not familiar with the internals of Tortoise, but it seems this PR changed the behavior, specifically around this area:
tortoise-orm/tortoise/queryset.py
Line 1182 in 54820ed
Maybe @henadzit can elaborate if we really need
f"{table.get_table_name()}.{field}"?