top-think / top-think/think-orm

There is no active transaction 错误出现的原因

Open
#224 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
437
Forks
188
PR merge metrics
No merged PRs in 30d

Description

下面这段代码不够严谨,希望能够处理一下
image

PDOConnection

public function transaction(callable $callback)
{
$this->startTrans();

    try {
        $result = null;
        if (is_callable($callback)) {
            $result = $callback($this);
        }

        $this->commit();
        return $result;
    } catch (\Exception | \Throwable $e) {
        $this->rollback();
        throw $e;
    }
}

这里面的 $this->rollback(); 这个一旦抛错,实际的错误就看不到了,其实实际的错误是
SQLSTATE[HY000]: General error: 1364 Field 'accessName' doesn't have a default value

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the PDOConnection::transaction entry point and read how commit and rollback errors are handled. Reproduce the shown case where the accessName field lacks a default value; done means the original SQLSTATE error remains visible even if rollback also fails.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.