Skip to content

A transaction is created and never terminated if flush throws an error. #801

@PetrAda

Description

@PetrAda

Describe the bug
A transaction is created and never terminated if flush throws an error.

To Reproduce

We have the following code snippet:

/**
 * @property int $id {primary}
 * @property DateTimeImmutable|null $createdAt {default now}
 * @property string|null $presenter
 * @property string|null $method
 * @property string|null $action
 * @property string|null $url
 * @property string|null $ip
 * @property string|null $request
 * @property User|null $user {m:1 User, oneSided=true}
 */
class Log extends AbstractEntity {}


function logRequest(): void
    {
        try {
            $log = new Log();
           $orm->getRepositoryForEntity($log)->attach($log);
            $log->user = $this->getUser()->isLoggedIn() ? (int)$this->getUser()->getId() : null;
            $log->createdAt = new DateTimeImmutable();
            $log->presenter = $this->getName();
            $log->action = $this->getAction();
            $log->url = $this->getHttpRequest()->getUrl()->getRelativeUrl();
            $log->method = $this->getHttpRequest()->getMethod();
            $log->ip = $this->getHttpRequest()->getRemoteAddress();
            $log->request = $request ?: null;
            $this->orm->persistAndFlush($log);
        } catch (\Exception) {
        }
    }

And a database which does NOT have the request column.
This results in an exception being thrown.

The SQL ONLY RUNS
BEGIN TRANSACTION

Steps to reproduce the behavior. It could include:

  1. Code which you run
  2. Definition of entities
  3. SQL table definitions
  4. Which SQL queries are executed

Expected behavior
A clear and concise description of what you expected to happen.

Versions::

  • Database: [PERCONA DB]
  • nextras/orm:v5.0.1
  • nextras/dbal:v5.0.7

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions