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

fix: db nil error during initiation #1423

Merged
merged 2 commits into from
May 21, 2024

Conversation

AvineshTripathi
Copy link
Collaborator

db db variable in the internal.go file was not populated by the utils.SetupDBConnection function and becuase of that the db.Dialect().Name() func returned a error in the NewApiHandler func stopping the server to start.

@Azanul
Copy link
Collaborator

Azanul commented May 17, 2024

@AvineshTripathi As far as I can see utils.SetupDBConnection function populates db when SQLite files or Postgres urls are available. This kind of change affects a larger pattern around how db (the global var) is initialised and used. Could you see why it wasn't being populated?

@AvineshTripathi
Copy link
Collaborator Author

@AvineshTripathi As far as I can see utils.SetupDBConnection function populates db when SQLite files or Postgres urls are available. This kind of change affects a larger pattern around how db (the global var) is initialised and used. Could you see why it wasn't being populated?

As you see https://github.com/tailwarden/komiser/pull/1423/files#diff-67213f39b84a013e7db04664cd3ad943b7a237d97b9c6e862d10806ac27def28L31 is by default <nil> since its not initialized and so when we pass it to db func it actually tries to populate the <nil> with new db which throws expections.

Apart from the PR another way to do this would be https://go.dev/play/p/ki1y6kY4lq2

@Azanul
Copy link
Collaborator

Azanul commented May 18, 2024

@AvineshTripathi

when we pass it to db func it actually tries to populate the with new db which throws expections.

I did not understand this part.

How has this been working all this time.

@AvineshTripathi
Copy link
Collaborator Author

when we are passing

var db *bun.DB

when we pass it to utils. SetupDBConnection, we are passing db=nil and trying to db to it, we are actually assign a db to nil value

https://github.com/tailwarden/komiser/pull/1423/files#diff-96521f49e302c910e49a7ecf0204bb81314694c3f216f60fc839c61a71b04b4bR37

and this must be broken with the recent major refactor

@Azanul
Copy link
Collaborator

Azanul commented May 18, 2024

when we are passing

var db *bun.DB

when we pass it to utils. SetupDBConnection, we are passing db=nil and trying to db to it, we are actually assign a db to nil value

https://github.com/tailwarden/komiser/pull/1423/files#diff-96521f49e302c910e49a7ecf0204bb81314694c3f216f60fc839c61a71b04b4bR37

and this must be broken with the recent major refactor

I see

Copy link
Collaborator

@Azanul Azanul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!

@Azanul Azanul merged commit e1cb5f1 into tailwarden:develop May 21, 2024
3 checks passed
@AvineshTripathi AvineshTripathi deleted the fix-db-init branch August 31, 2024 15:07
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 this pull request may close these issues.

2 participants