mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
No exception thrown while insert if the sequence is not found using postgresql #5448
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Hendra-Huang on GitHub (Mar 7, 2017).
My detail case is like this.
At first my entity looks like this
I generate the schema, so I have got table X in my database. Then I want to rename my table and schema. So my entity now looks like this
I update the schema again and manually rename table X to table Y in the database. Everything seems working fine. But something weird happens. All insert operations to
Class Yare not persisted to the database, meanwhile no exception thrown while persist and flush. We wasted several hours for finding the problem because no exception at all. At last, we find out that the problem is because there is a different between table name and sequence name. We rename the table without renaming the sequence name. I think its better if there is an exception thrown because of it.@Ocramius commented on GitHub (Mar 12, 2017):
If an SQL operation fails, an exception will be thrown.
What does the SQL log say? Why are those statements executed and fail, but exceptions are not bubbling up?
Can this be reproduced in isolation in DBAL?
@Hendra-Huang commented on GitHub (Mar 13, 2017):
This issue can't be reproduced in DBAL and the data is persisted to the database. Meanwhile in ORM, the data is not persisted and there is no exception thrown.
This is the way i do it. I started a new symfony project with
pdo_pgsqldriver and create a new Entity.Then I run
bin/console doctrine:database:createandbin/console doctrine:schema:create --force. As the result, I got a table named "a" in my database. I run a query in the database to show the fields and sequence of table "a".I modified the
DefaultController.phpto insert into table "a".It's working as expected. The data is persisted to table "a".
Then I rename my table "a" to "b" in my entity.
@ORM\Table(name="a")to@ORM\Table(name="b"). I run SQL query from command line to update the table name.ALTER TABLE a RENAME TO b;. Then I try again and there is no error or exception at all and the data is not persisted. Here is mydev.log.This is the version I used for this project.
@Ocramius commented on GitHub (Mar 13, 2017):
The insert statement is there: are you looking at the correct db/schema?
On 13 Mar 2017 14:13, "Hendra-Huang" notifications@github.com wrote:
@Hendra-Huang commented on GitHub (Mar 13, 2017):
Yeah there is the insert statement and it's using correct db and table. The problem is that the value of the inserted "id" column is always 1. Actually in my table, I have some records and the next id must not be 1. The problem is that I rename the table without rename the sequence. If I rename the sequence, then everything works as expected.
@Ocramius commented on GitHub (Mar 24, 2017):
@Hendra-Huang doesn't look like an ORM bug to me then: if your DB silently accepts the value, that's expected behavior due to missing schema constraints.
If the problem is the lack of rename in the constraint, then I suggest writing a reproduction test case and reporting it against https://github.com/doctrine/dbal
@msztolcman commented on GitHub (Jul 5, 2017):
I had same problem, with changed name of primary key field (without changed sequence name). Created entity, persist & flush, commit. Nothing in DB, no exception at all. But when I manually looked into PDO errors:
$this->logger->debug("SQL ERROR INFO: " . print_r($this->em->getConnection()->errorInfo(), 1));There was info about invalid sequence. Fixing sequence name to expected by doctrine helps, but any exception from doctrine would be useful :)
@Ocramius commented on GitHub (Jul 7, 2017):
Relevant: