Skip to content

fix: [#738] The Orm Creating event can be triggered when the query with the Model method#1167

Merged
hwbrzzl merged 2 commits intomasterfrom
bowen/#738-2
Aug 20, 2025
Merged

fix: [#738] The Orm Creating event can be triggered when the query with the Model method#1167
hwbrzzl merged 2 commits intomasterfrom
bowen/#738-2

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Aug 20, 2025

📑 Description

Closes goravel/goravel#738

✅ Checks

  • Added test cases for my code

…th the Model method (#1166)

* fix: [#738] The Orm Creating event can be triggered when the query with the Model method

* fix tests
@codecov
Copy link

codecov bot commented Aug 20, 2025

Codecov Report

❌ Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.60%. Comparing base (9bb4da6) to head (e2bb899).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
errors/errors.go 0.00% 2 Missing ⚠️
support/file/file.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1167      +/-   ##
==========================================
- Coverage   68.61%   68.60%   -0.02%     
==========================================
  Files         223      223              
  Lines       14480    14475       -5     
==========================================
- Hits         9936     9930       -6     
- Misses       4168     4169       +1     
  Partials      376      376              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hwbrzzl hwbrzzl marked this pull request as ready for review August 20, 2025 10:11
Copilot AI review requested due to automatic review settings August 20, 2025 10:11
@hwbrzzl hwbrzzl requested a review from a team as a code owner August 20, 2025 10:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where ORM creating events were being incorrectly triggered when using Model methods with slice data or mass operations. The fix ensures that model events are only triggered for single record operations, not for batch operations or slice data.

  • Added checks to prevent event triggering for slice data in create, save, update, delete, and retrieve operations
  • Refactored error handling throughout the codebase to use a new errors.Ignore() utility function
  • Added comprehensive test coverage for the event triggering behavior with slice data and mass operations

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
database/gorm/query.go Added slice and ID validation to prevent inappropriate event triggering
errors/errors.go Added new Ignore() utility function for simplified error handling
tests/query_test.go Added test cases to verify events are not triggered for slice operations
tests/models.go Added panic conditions to catch incorrect event triggering scenarios
Multiple files Refactored defer statements to use errors.Ignore() for cleaner error handling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@hwbrzzl hwbrzzl merged commit a4a1e40 into master Aug 20, 2025
14 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#738-2 branch August 20, 2025 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Orm Creating event can be triggered when the query with the Model method

2 participants