Skip to content

fix(obligation_creation): pass user name in context for the db call w… #128

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mayank-pathakk
Copy link

@mayank-pathakk mayank-pathakk commented Mar 25, 2025

…hile creating obligations

Changes

As mentioned in the associated issue we were getting the following error:
username not found in context. This was due to the hook we had in our license model.

func (l *LicenseDB) BeforeCreate(tx *gorm.DB) error {
	username, ok := tx.Statement.Context.Value(ContextKey("user")).(string)
	if !ok {
		return errors.New("username not found in context")
	}
	...
}

Now since we were not passing the user in the context, we were unable to figure out the username and hence we were getting the error.

Submitter Checklist

  • Includes tests (if there is a feature changed/added)
  • Includes docs ( if changes are user facing) [Nothing changes for the end user]
  • I have tested my changes locally.

References

Screenshot 2025-03-25 at 3 54 49 PM

@mayank-pathakk
Copy link
Author

@GMishx @deo002 Please review. This change would include the user name in the context and hence will fix the issue.
Thanks in advance.

@ChayanDass
Copy link
Contributor

ChayanDass commented Mar 25, 2025

Hi @mayank-pathakk sir,
yes, this will solve the issue but the issue is beforecreate hook for license should not be called during creation of obligation....

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.

obligations creating error with shortnames
2 participants