Skip to content

Firebase dataconnect transaction (emulator) #8658

Closed

Description

@federicobaiocco

[REQUIRED] Environment info

14.4.0

firebase-tools: 14.4.0

Platform: macOS

[REQUIRED] Test case

Trying to run a transaction with multiple deletes/inserts fails with errror message: cannot commit transaction: pq: unexpected transaction status idle (when running on dataconnect emulator)

[REQUIRED] Steps to reproduce

Create a mutation:

mutation Example($id: String) @auth(level: NO_ACCESS) @transaction {
  productTag_deleteMany(where: { productId: { eq: $id }})

  product_upsert(data: {
    id: $id
    name: "Dummy Product"
    type: "DIGITAL"
    active: true
    createdAt: "2025-05-27T10:00:00Z"
    updatedAt: "2025-05-27T10:00:00Z"
    language: "en"
    publicationDate: "2025-06-01"
    metadataStatus: "Draft"
  })

  productCategory_insertMany(data: [
    { productId: $id, categoryCode: "ABC123" }
  ])
}

It works without the @transaction

[REQUIRED] Expected behavior

Run all the deletes/inserts within a transaction

[REQUIRED] Actual behavior

Fails with error message: cannot commit transaction: pq: unexpected transaction status idle

I0527 07:16:09.343656 76082 prepare.go:118] [operation "Test" attempt 1] preparePlan succeeded
I0527 07:16:09.343690 76082 prepare.go:109] [operation "Test" attempt 1] DBStats beforePrepare: sql.DBStats{MaxOpenConnections:1, OpenConnections:1, InUse:0, Idle:1, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}, afterPrepare: sql.DBStats{MaxOpenConnections:1, OpenConnections:1, InUse:0, Idle:1, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}
I0527 07:16:09.354744 76082 executor.go:97] [operation "Test" attempt 1] DBStats beforeRun: sql.DBStats{MaxOpenConnections:1, OpenConnections:1, InUse:0, Idle:1, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}, afterRun: sql.DBStats{MaxOpenConnections:1, OpenConnections:0, InUse:0, Idle:0, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}
W0527 07:16:09.355025 76082 engine.go:174] [/emulator/distribution-platform-service-dev afa1] ExecuteGraphql Test: failed.
Auth: admin
Variables:
{
"id": "c4645212-0c2d-41bb-b867-9f83e442cbb1"
}
Errors: input: cannot commit transaction: pq: unexpected transaction status idle

Activity

  1. federicobaiocco commented on May 27, 2025

    @federicobaiocco
    Author

    Update: Running the exact same mutation on firebase console works. It only fails when running on emulator

  2. changed the title [-]Firebase dataconnect transaction[/-] [+]Firebase dataconnect transaction (emulator)[/+] on May 27, 2025
  3. added
    emulator: dataconnect
    on May 27, 2025
  4. Cruzor-Blade commented on May 27, 2025

    @Cruzor-Blade

    I am witnessing exactly the same errors. I was trying to delete many elements, after filtering.
    And even upsert transactions fail too.
    I am on firebase tools 14.4.0 and node 22.

    Edit: Seems that all mutations are not working.
    For my particular case, I am running the mutations under firebase-admin.
    Getting the error

    ExecuteGraphql : failed with explicit status error: rpc error: code = PermissionDenied desc = unauthorized: you are not authorized to perform this operation.
    

    even though I am impersonating a validated token with impersonate: {authClaims: {sub: uid}} under the privileged environment

  5. aalej commented on May 29, 2025

    @aalej
    Contributor

    Thanks for raising this and for filing a detailed report @federicobaiocco! I was able to reproduce the error when using @transaction. As you mentioned, when using the emulators, the same mutation without @transaction works. Also verified that the same mutation(with @transaction) works on production. So this seems like a bug on the emulator.

    Just to note, even though an error was raised, it seems like the transaction still went through since product tag deletion, product upsert, and product category insert were successful.

    Let me check this with our engineering team. Sharing the mcve here.

  6. joehan commented on May 29, 2025

    @joehan
    Member

    @Cruzor-Blade I think you are facing a different problem - could you open a separate issue for that (with an MCVE if possible)?

  7. mr13tech commented on Jun 3, 2025

    @mr13tech

    I also having this problem today - was setting up new machine and everything is red after latest firebase-tools install. Had to remove @transaction adnotations from seed mutations.

  8. joehan commented on Jun 24, 2025

    @joehan
    Member

    This issue is fixed as of 14.8.0. Sorry for the inconvenience all!

  9. federicobaiocco commented on Jun 24, 2025

    @federicobaiocco
    Author

    This issue is fixed as of 14.8.0. Sorry for the inconvenience all!

    Excellent thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

emulator: dataconnectreproducibletype: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions