Skip to content

fix(obligations_creation): Ensure license BeforeCreate hook runs only during creation (#121) #122

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 4 commits into
base: main
Choose a base branch
from

Conversation

ChayanDass
Copy link
Contributor

@ChayanDass ChayanDass commented Mar 22, 2025

Problem

When creating an Obligation with shortnames, the BeforeCreate hook is triggered due to the licensedb being associated with shortames. However, this leads to a username not found in context error

Changes

  • Refactored the BeforeCreate hook to run only during creation by adding check.
  • Improved efficiency by preventing redundant operations during updates. (it will ensure beforecreate hook only run on creation not on update )
  • Fixes obligations creating error with shortnames #121

Submitter Checklist

  • Includes tests (if there is a feature changed/added)
  • Includes docs (if changes are user-facing)
  • I have tested my changes locally.

References

  • no problem on creation of obligation
    image

  • on problem on creation of license

Screenshot from 2025-03-22 16-46-08

@ChayanDass ChayanDass force-pushed the fix/obligations-creation-issue-#121 branch 2 times, most recently from 72b1caf to 24a20e2 Compare March 22, 2025 11:23
@ChayanDass
Copy link
Contributor Author

@deo002 , can you please review this pr ?

@deo002
Copy link
Collaborator

deo002 commented Mar 24, 2025

Ideally, on obligation creation, the BeforeCreate hook(for Licenses) shouldn't run as the Licenses to be associated already exist and aren't new. A good approach would be to ensure BeforeCreate doesn't run in this case instead of adding a check in it. What do you suggest?

However, on creating an obligation, GORM treats the licenses in o.Licenses array as new records and creates them if they do not already exist instead of treating them as existing records. This triggers the BeforeCreate hook for licenses.

Can we first create the obligation and then associate existing licenses to it via associations? This way, BeforeCreate hook wont run.

@deo002 deo002 self-requested a review March 24, 2025 10:20
@deo002 deo002 assigned deo002 and unassigned deo002 Mar 24, 2025
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