Closed kbhalerao closed 6 months ago
i am getting this same issue in a fresh django project
python = 3.10
Django = 4.0.5
psycopg2 = 2.9.3
django-hordak = 1.10.2
postgres (PostgreSQL) 14.2 (Debian 14.2-1.pgdg110+1)
Adding a new migration fixed it for me. By replacing
IF NEW.parent_id::BOOL THEN
with IF NEW.parent_id::INT::BOOL THEN
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("hordak", "0029_alter_leg_amount_currency_and_more")]
operations = [
migrations.RunSQL(
"""
CREATE OR REPLACE FUNCTION check_account_type()
RETURNS TRIGGER AS
$$
BEGIN
IF NEW.parent_id::INT::BOOL THEN
NEW.type = (SELECT type FROM hordak_account WHERE id = NEW.parent_id);
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
""",
"DROP FUNCTION check_account_type()",
)
]
@kbhalerao @lalatgithub I would like to release fix for this, but I would need to be able to replicate. It works fine on my project as well as in tests all using PostgreSQL.
Do you use some settings that might be responsible for this such as:
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
?
Yeah. I can confirm, that this problem is specific to using BigAutoField
. I will try to make the fix migration.
it looks like this was fixed in migration 0032_check_account_type_big_int.py
. I'll close this
To replicate:
Account
, results inWorkaround: Change the trigger code to do an intermediate cast from BigInt to Int, as follows. Might fail in weird ways I don't understand. Probably needs to be set up in the migration