Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instance.admin.(email for example) returns the last user created #18

Open
diligiant opened this issue Feb 7, 2023 · 7 comments · May be fixed by #28
Open

instance.admin.(email for example) returns the last user created #18

diligiant opened this issue Feb 7, 2023 · 7 comments · May be fixed by #28

Comments

@diligiant
Copy link

diligiant commented Feb 7, 2023

Hi,

That's probably a "gorm magic" issue and I really have no idea how to solve it. Check my test server (https://none.com/api/v1/instance/). You'll see that email, contact_account is myself although the serializer processes the i.Admin (admin@).
When I check instances and accounts in Mariadb, this confirms that it holds the right info (see below).

Any hint/solution would be great.

thank you.

Frédéric

select admin_id from instances;
+--------------------+
| admin_id           |
+--------------------+
| 109694405584505771 |
+--------------------+
select id, actor_id, email from accounts;
+--------------------+--------------------+--------------------+
| id                 | actor_id           | email              |
+--------------------+--------------------+--------------------+
| 109694405584505771 | 109694405584200435 | [email protected]   |
select id,name from actors where id=109694405584200435;
+--------------------+-------+
| id                 | name  |
+--------------------+-------+
| 109694405584200435 | admin |
+--------------------+-------+
@davecheney
Copy link
Owner

thanks for spotting that; back in the day the instance admin was a total hack which was just finding a random account with a matching domain. I suspect that logic is still lurking around.

@diligiant
Copy link
Author

I was under the impression the gorm magic wasn't working as before adding a LocalUser account, the correct info were returned but if you think that's "intentional", I'm gonna find this culprit ;)

@diligiant diligiant linked a pull request May 7, 2023 that will close this issue
@diligiant
Copy link
Author

diligiant commented May 7, 2023

@davecheney I hope my PR will satisfy you ; I was really frustrated by this problem. I found 2 other occurrences (hoping I caught them all.)

Something puzzles me though: gorm documentation describes

type instance struct {
…
AdminID          *snowflake.ID
Admin            *Account
}

type Account {
snowflake.ID
}

as a Belongs To association, "the instance belongs to the admin account".

Shouldn't this be instead an Has One, "the instance has one admin account"? If so, one should take a look the the many associations in your schema.

my 2¢

@davecheney
Copy link
Owner

Damnit, did I break that again?

@diligiant
Copy link
Author

It never worked (I found this when I first played with pub) as it never could (and I bet that's also true with Relationship & Status.)
gorm is tricky (I almost rewrote with sqlc ;) here as its "convention" isn't "the previous field is named like the association field+primarykey". That's very subtle…

Regarding BelongsTo vs HasOne, I don't know if that changes anything today but isn't this a bet that gorm won't do things differently in the future?

@davecheney
Copy link
Owner

I get very confused by HasOne vs BelongsTo in gorm.

@diligiant
Copy link
Author

you, me and a million people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants