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
I am creating a many 2 many table with one primary key as bigserial auto-increment and then the two FK with a unique group.
The two foreign keys ids are UUIDs.
The tables look like that:
typeUserTeststruct {
ID uuid.UUID`pg:",type:uuid"`Permissions []PermissionTest`pg:"many2many:upt"`
}
typePermissionTeststruct {
ID uuid.UUID`pg:",type:uuid"`
}
typeUsersPermissionsTeststruct {
tableNamestruct{} `pg:"upt"`IDint`pg:"id,pk"`PermissionID uuid.UUID`pg:"permission_test_id,type:uuid,unique:idx_upt_unique"`UserID uuid.UUID`pg:"user_test_id,type:uuid,unique:idx_users_upt_unique"`
}
Current Behavior
When fetching the relation of the many 2 many table instead of setting the permission id to the corresponding column in the select the ORM is trying to set the pk which is int to the FK permission id which is a UUID. (IDK if it's clear)
This is the final selection:
SELECT "users_permissions_test".*, "permission_test"."id" FROM "permission_tests" AS "permission_test"
JOIN "upt" AS "users_permissions_test" ON ("users_permissions_test"."user_test_id") IN ('25289c7f-e733-4903-a8a3-e1569712ea69')
WHERE ("permission_test"."id" = "users_permissions_test"."permission_test_id")
The ORM is trying to assign "user_permissions_test"."id" to the Permission.ID struct. Which lead to panic: uuid: incorrect UUID length
This error happens with the UUID type. If you replace Permissions Ids and User ids with int it works suddenly as expected. The Permission.ID is correctly set from the "user_permissions_test"."permission_test_id" and not from the "user_permissions_test"."id". (that is surprising)
Expected Behavior
The ORM must correctly set the Permission ID from the "user_permissions_test"."permission_test_id" and not from the "user_permissions_test"."id".
Possible Solution
Yesterday I was diving into your code and it seems like the many to many scanner have an empty columns map field while scanning the first column (which is the id from user_permissions_test).
Likely too deep to understand why this bug happens. I just saw today that the problem only appear with UUID I first though that it was a bug because my foreign keys aren't the primary composite key, but it's not the case.
I am creating a many 2 many table with one primary key as bigserial auto-increment and then the two FK with a unique group.
The two foreign keys ids are UUIDs.
The tables look like that:
Current Behavior
When fetching the relation of the many 2 many table instead of setting the permission id to the corresponding column in the select the ORM is trying to set the pk which is int to the FK permission id which is a UUID. (IDK if it's clear)
This is the final selection:
The ORM is trying to assign
"user_permissions_test"."id"
to the Permission.ID struct. Which lead topanic: uuid: incorrect UUID length
This error happens with the UUID type. If you replace Permissions Ids and User ids with int it works suddenly as expected. The Permission.ID is correctly set from the
"user_permissions_test"."permission_test_id"
and not from the"user_permissions_test"."id"
. (that is surprising)Expected Behavior
The ORM must correctly set the Permission ID from the
"user_permissions_test"."permission_test_id"
and not from the"user_permissions_test"."id"
.Possible Solution
Yesterday I was diving into your code and it seems like the many to many scanner have an empty
columns
map field while scanning the first column (which is the id fromuser_permissions_test
).Likely too deep to understand why this bug happens. I just saw today that the problem only appear with UUID I first though that it was a bug because my foreign keys aren't the primary composite key, but it's not the case.
Steps to Reproduce
Launch this code:
You should have this output:
Context (Environment)
I'm just trying to bind what I have in my database. The link table has fields with the id as a primary key and two other FK as UUIDs.
There is no black magic it's a simple case, I don't know why it isn't working, I was expecting it to works.
The text was updated successfully, but these errors were encountered: