Repository: typeorm/typeorm
File: test/functional/query-builder/locking/query-builder-locking.ts (TypeScript)

Code before:
                    })
                    .should.be.rejectedWith(
                        'relation "img" in FOR UPDATE clause not found in FROM clause',
                    )
            }),
        ))

    it("should allow on a left join", () =>
        Promise.all(
            connections.map(async (connection) => {
                if (connection.driver.options.type === "cockroachdb") {
                    return connection.manager.transaction((entityManager) => {
                        return Promise.all([
                            entityManager
                                .createQueryBuilder(Post, "post")
                                .leftJoin("post.author", "user")
                                .setLock("pessimistic_write", undefined, [
                                    "post",
                                ])
                                .getOne(),
                            entityManager
                                .createQueryBuilder(Post, "post")
                                .leftJoin("post.author", "user")
                                .setLock("pessimistic_write")
                                .getOne(),
                        ])
                    })
                }

                if (connection.driver.options.type === "postgres") {
                    return connection.manager.transaction((entityManager) => {
                        return Promise.all([
                            entityManager
                                .createQueryBuilder(Post, "post")
                                .leftJoin("post.author", "user")
                                .setLock("pessimistic_write", undefined, [
                                    "post",
                                ])
                                .getOne(),
                            entityManager
                                .createQueryBuilder(Post, "post")
                                .leftJoin("post.author", "user")
                                .setLock("pessimistic_write")
                                .getOne()
                                .should.be.rejectedWith(
                                    "FOR UPDATE cannot be applied to the nullable side of an outer join",
                                ),
                        ])
                    })
                }


Review comment (bug):
This seems to be breaking the transaction and making `RELEASE SAVEPOINT` unavailable: https://www.cockroachlabs.com/docs/stable/release-savepoint#handling-errors

Because Chai does not forward the error, `Promise.all` will not throw either, making `EntityManager.transaction` think the operation was successful, so it won't roll back.

We should probably make that function fail.

Code after:
                    })
                    .should.be.rejectedWith(
                        'relation "img" in FOR UPDATE clause not found in FROM clause',
                    )
            }),
        ))

    it("should allow on a left join", () =>
        Promise.all(
            connections.map(async (connection) => {
                if (connection.driver.options.type === "cockroachdb") {
                    return connection.manager.transaction((entityManager) => {
                        return Promise.all([
                            entityManager
                                .createQueryBuilder(Post, "post")
                                .leftJoin("post.author", "user")
                                .setLock("pessimistic_write", undefined, [
                                    "post",
                                ])
                                .getOne(),
                            entityManager
                                .createQueryBuilder(Post, "post")
                                .leftJoin("post.author", "user")
                                .setLock("pessimistic_write")
                                .getOne()
                                .should.be.rejectedWith(
                                    "FOR UPDATE cannot be applied to the nullable side of an outer join",
                                ),
                        ])
                    })
                }

                if (connection.driver.options.type === "postgres") {
                    return connection.manager.transaction((entityManager) => {
                        return Promise.all([
                            entityManager
                                .createQueryBuilder(Post, "post")
                                .leftJoin("post.author", "user")
                                .setLock("pessimistic_write", undefined, [
                                    "post",
                                ])
                                .getOne(),
                            entityManager
                                .createQueryBuilder(Post, "post")
                                .leftJoin("post.author", "user")
                                .setLock("pessimistic_write")
                                .getOne()
                                .should.be.rejectedWith(
                                    "FOR UPDATE cannot be applied to the nullable side of an outer join",
                                ),
                        ])