Skip to content

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

Closed
ChayanDass wants to merge 1 commit intofossology:mainfrom
ChayanDass:fix/obligations-creation-issue-#121
Closed

fix(obligations_creation): Ensure license BeforeCreate hook runs only during creation (#121)#122
ChayanDass wants to merge 1 commit intofossology:mainfrom
ChayanDass:fix/obligations-creation-issue-#121

Conversation

@ChayanDass
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@deo002 , can you please review this pr ?

@deo002
Copy link
Copy Markdown
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
@ChayanDass ChayanDass force-pushed the fix/obligations-creation-issue-#121 branch from 24a20e2 to e5c3664 Compare March 24, 2025 17:03
@deo002
Copy link
Copy Markdown
Collaborator

deo002 commented Jul 9, 2025

I am really sorry for not checking this PR until now Chayan. Could you rebase it with the current main or open a new PR, which ever one is easier? Thanks!

@ChayanDass ChayanDass force-pushed the fix/obligations-creation-issue-#121 branch from ff48272 to 446cc07 Compare July 9, 2025 10:11
@ChayanDass
Copy link
Copy Markdown
Contributor Author

Closing in favour of #149

@ChayanDass ChayanDass closed this Jul 11, 2025
@ChayanDass ChayanDass deleted the fix/obligations-creation-issue-#121 branch July 11, 2025 09:39
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