Skip to content

fix: [#762] handle panic when using transaction#1184

Merged
hwbrzzl merged 1 commit intov1.15.xfrom
bowen/#762-1
Sep 6, 2025
Merged

fix: [#762] handle panic when using transaction#1184
hwbrzzl merged 1 commit intov1.15.xfrom
bowen/#762-1

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Sep 6, 2025

📑 Description

Closes goravel/goravel#762

This pull request improves the reliability of transaction handling in the ORM package by ensuring that panics within transactions are properly caught and handled, preventing partial data writes and making error reporting more robust. Additionally, a new test is added to verify this behavior, and the package version is incremented.

Transaction reliability improvements:

  • Updated the Transaction method in orm.go to catch panics, roll back the transaction, and return a formatted error, ensuring that panics do not leave the database in an inconsistent state.
  • Imported the errors package in orm.go to support error joining for rollback failures during panic handling.

Testing enhancements:

  • Added TestTransactionPanic in orm_test.go to verify that panics during a transaction are handled correctly, the transaction is rolled back, and no data is written.
  • Imported the fmt package in orm_test.go to support formatted error comparisons in tests.

Version update:

  • Bumped the package version in support/constant.go from v1.15.11 to v1.15.12 to reflect these improvements.

✅ Checks

  • Added test cases for my code

Copilot AI review requested due to automatic review settings September 6, 2025 09:31
@hwbrzzl hwbrzzl requested a review from a team as a code owner September 6, 2025 09:31
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 pull request improves transaction reliability by adding panic handling to prevent partial database writes and ensure proper cleanup when transactions fail unexpectedly.

  • Added panic recovery in the Transaction method to catch panics, rollback transactions, and return formatted errors
  • Enhanced testing with a new test case that verifies panic handling behavior during transactions
  • Incremented package version to reflect these reliability improvements

Reviewed Changes

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

File Description
support/constant.go Version bump from v1.15.11 to v1.15.12
database/orm/orm_test.go Added fmt import and TestTransactionPanic test case
database/orm/orm.go Added errors import and panic recovery logic in Transaction method

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

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 0ce89d5 Previous: 4cd93b0 Ratio
Benchmark_DecryptString 6606 ns/op 2040 B/op 17 allocs/op 2170 ns/op 2032 B/op 16 allocs/op 3.04
Benchmark_DecryptString - ns/op 6606 ns/op 2170 ns/op 3.04
Benchmark_Debug 175073 ns/op 47977 B/op 661 allocs/op 115588 ns/op 29160 B/op 529 allocs/op 1.51
Benchmark_Debug - ns/op 175073 ns/op 115588 ns/op 1.51
Benchmark_Debug - B/op 47977 B/op 29160 B/op 1.65
Benchmark_Info 175210 ns/op 48057 B/op 659 allocs/op 115865 ns/op 29053 B/op 527 allocs/op 1.51
Benchmark_Info - ns/op 175210 ns/op 115865 ns/op 1.51
Benchmark_Info - B/op 48057 B/op 29053 B/op 1.65
Benchmark_Warning 190112 ns/op 50022 B/op 691 allocs/op 120574 ns/op 29875 B/op 537 allocs/op 1.58
Benchmark_Warning - ns/op 190112 ns/op 120574 ns/op 1.58
Benchmark_Warning - B/op 50022 B/op 29875 B/op 1.67

This comment was automatically generated by workflow using github-action-benchmark.

@codecov
Copy link

codecov bot commented Sep 6, 2025

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (v1.15.x@8c1b39a). Learn more about missing BASE report.

Files with missing lines Patch % Lines
database/orm/orm.go 57.14% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             v1.15.x    #1184   +/-   ##
==========================================
  Coverage           ?   68.68%           
==========================================
  Files              ?      219           
  Lines              ?    18968           
  Branches           ?        0           
==========================================
  Hits               ?    13029           
  Misses             ?     5261           
  Partials           ?      678           

☔ 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 merged commit 890a8b1 into v1.15.x Sep 6, 2025
12 of 13 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#762-1 branch September 6, 2025 13:30
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.

1 participant