Skip to content

feat: user service uses database.QueryExecutor - #263

Closed
IAM-marco wants to merge 2 commits into
mainfrom
feat/refactor-user-service
Closed

feat: user service uses database.QueryExecutor#263
IAM-marco wants to merge 2 commits into
mainfrom
feat/refactor-user-service

Conversation

@IAM-marco

@IAM-marco IAM-marco commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Problem

userService.SetPassword() needs to start a transaction or re-use an existing one. However, database.Pool, which is what is used by userService to access DB, has no idea of whether a transaction is started or not. This is the DB client job. So, when trying to create a password for a user in an already open transaction, the procedure fails, because the system attempts to open another transaction, instead of re-using the existing one.

Solution

  • Switch database.Pool paramter to database.QueryExecutor
  • Type assert db client on database.Beginner to make sure the client can handle transaction
  • Use beginner.Begin() to gracefully start a new transaction or re-use the existing one

Extras

  • Create missing mocks
  • Add tests for SetPassword

…ry, UserPasswordRepository, and crypto.Hasher
test: add unit tests for UserService.SetPassword
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

@IAM-marco must be a member of the zitadel team on Vercel to deploy.
- Click here to add @IAM-marco to the team.
- If you initiated this build, request access.

Learn more about collaboration on Vercel and other options here.

@IAM-marco
IAM-marco requested a review from vitorbari June 11, 2026 15:17
Comment thread internal/service/user.go
return domain.ErrInternal(database.ErrNotABeginner)
}

tx, err := beginner.Begin(ctx, nil)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One of the goals, is to be able to call CreateUser and SetPassword within the same transaction. How will this nested transaction behave?

@IAM-marco

Copy link
Copy Markdown
Contributor Author

Closing as we are migrating to a new approach to handle expensive cryptographic ops outside of DB tx

@IAM-marco IAM-marco closed this Jun 12, 2026
@fforootd
fforootd deleted the feat/refactor-user-service branch June 16, 2026 20: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