Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

No. Calling a service from inside a Prisma transaction callback does not make that service’s database queries part of the transaction. The query’s Prisma client determines whether it participates: a query through the callback’s transaction-bound tx client is in the transaction; a query through an injected default this.prisma client is not automatically included. In a delivery-backend bug described by backend engineer Mhamd Ghanoum, an order remained in PostgreSQL after a later event-log step failed because the service used its own client. The fix was to pass the transaction client into the service and use it for the write.

Why didn’t the transaction roll back the order?

Because the order write and event-log write did not both use the transaction-bound client. In the bug Ghanoum describes, the caller wrapped order creation and event logging in an interactive transaction callback, then deliberately made event logging fail to check whether the order would roll back. It did not: the order was created, but no event history was recorded.

The key detail was inside EventLogService.recordEvent. It called this.prisma.eventLog.create(...), using the service’s injected default Prisma client rather than the tx object supplied to the callback. That query ran outside the caller’s open transaction and could commit independently. The code was nested inside the callback in the source file, but its query was not part of the transaction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

As Ghanoum puts it, “Code structure and transaction membership are two different things.” The call stack can show that a service method was reached during a transaction callback; it cannot make a query issued through another client join that transaction.

Popular on Amazon
Silkland 40Gbps USB C 90 Degree Right Angle Adapter 2 Pack, 240W USB4 | Male to Female Extender, 8K@60Hz, Thunderbolt 4/3, Steam Deck, ROG Ally, MacBook, Switch 2, iPhone 18/17/16/15, Quest 3 VR
  • 【90 Degree Full Function USB C Adapter】Supports the latest USB4 standard for up to 40Gbps of bandwidth, 8K video support, and up to 240W Fast charging; Support USB PD 3.1 Extended Power Range (EPR) including 140W, 180W and 240W. Your productivity is easily doubled. *Warm Tip: For the best fit, please make sure the USB-C port is fully exposed; thick or bulky cases may affect compatibility.
  • 【Reliable Quality】Made from high-quality, scratch-resistant aluminum alloy, delicate metal frame. get excellent wear resistance and heat dissipation. Non-Slip Design for easier insertion and removal.
  • 【Small and portable】Ultra thin size, ultra compact design, a petite physique that matches the minimalist design of your modern laptops. Coming with a slim figure that won't block the port next to the one it's plugged into.
  • 【Compatibility】Widely work with most usb c, thunderbolt 4/3 devices. Compatibilit for ROG Ally, Steam Deck, Switch, MacBook Pro, Quest 3 VR headset, Surface Book 2, iPhone 18/17/16/15, Samsung Galaxy S23/S22/S21, Note 20/10, Google Pixel, ChromeBook, etc.
  • 【Excellence Customer Support】If you experience any issues or cable failure, simply reach out to our dedicated customer service team. We provide a prompt response within 18 hours, providing you with the necessary technical support to resolve any concerns.

What decides whether a query is inside a Prisma transaction?

The client object that executes the query decides. An interactive Prisma transaction provides a transaction-bound client to its callback. Use that client for each database query that must participate in the transaction; an ordinary injected client does not automatically inherit the callback’s transaction context.

Prisma’s transaction guidance states the operational rule plainly: use tx for every query inside the callback. The rule applies across service boundaries, not just to queries written inline in the callback. If a service method runs a database operation, inspect which client that operation actually calls.

  • Through tx: the query participates in the open transaction. If the callback throws, the transaction’s database writes can roll back together.
  • Through the default client: the query is outside that transaction. It may commit independently, even if the call that triggered it happened while the callback was running.

This is why a service’s injected client is not interchangeable with the transaction client for atomic work. Both clients may expose similar model operations, but the client used for a query determines its transaction membership. Function nesting, dependency injection, and naming conventions do not substitute for passing the transaction-bound client explicitly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How should a service share the transaction client?

Make a transaction-capable method accept an optional transaction client, select that client when the caller supplies one, and pass tx at the call site. When no transaction client is supplied, the service can retain its default-client behavior for standalone use.

Also popular on Amazon
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

1. Let the method accept a transaction client

async recordEvent(params, tx?: Prisma.TransactionClient) {
  const client = tx ?? this.prisma;
  return client.eventLog.create({ data: params });
}

Here, the method chooses its query client once: it uses the supplied transaction client when available, otherwise it falls back to the injected default client. This makes the distinction visible in the method signature instead of assuming a transaction will appear implicitly.

2. Pass the callback client when calling the service

await this.eventLogService.recordEvent(params, tx);

The call site must pass the same tx received by the transaction callback. If it omits the argument, the service falls back to this.prisma, and that call will not join the caller’s transaction.

3. Keep all related writes on that client

Apply the same pattern to every service operation that writes data that must commit or roll back with the order. Passing tx to event logging while another helper still uses its own default client leaves the workflow split: only the queries issued through the transaction-bound client are covered by that transaction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Ghanoum’s reported failure scenario, after the service accepted and used the passed transaction client, rerunning the failure case caused the order and event work to roll back together. The correction was client propagation, not merely moving the service call into a different place in the callback.

Also popular on Amazon
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Why not open another transaction inside the helper?

A helper that starts its own transaction does not create a nested transaction that the caller’s transaction controls. The helper’s transaction is separate; the outer transaction cannot roll back work that the helper committed independently.

For a write that must be atomic with its caller’s work, pass the existing transaction client down and use it. Starting a new transaction in a helper changes the boundary rather than extending the outer one. Prisma’s guidance for helper functions follows the same pattern: accept tx as an argument and invoke the helper with the transaction client.

This matters even when a helper is intended to “be safe” by wrapping its own database work in a transaction. That may group the helper’s own queries, but it does not make those queries part of an already-open transaction around the caller’s larger operation. Decide where the atomic boundary belongs, then propagate that boundary’s client through the calls that need to share it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does the code use the right Prisma transaction API for my version?

Check the Prisma ORM version used by the project before copying transaction syntax. The example in this article uses the title’s Prisma ORM 7-style prisma.$transaction form; current Prisma ORM 8 documentation uses db.transaction(async (tx) => { ... }) instead.

Also popular on Amazon
BENFEI USB C Hub 5-in-1 with 4K HDMI(Certified), 100W Power Delivery, 3 USB-A, Silicone Cable, Aluminum Case Compatible with MacBook Pro/Air, iPad Pro, iMac, iPhone 15 Pro/Pro Max, XPS, Thinkpad
  • Portable and powerful USB-C HUB: BENFEI USB Type-C HUB, with super-soft and knot-free silicone woven design cable, meets most mobile office needs. Compact, lightweight, stylish, and powerful portable USB C Hub equipped with 1 x HDMI port, 1 x 100W charging, and 3 x USB ports. 18-month warranty, 24-hour response, to ensure you feel at ease when using our product.
  • Design centered on comfort and reliability: Thanks to BENFEI's end-to-end in-house cable production capability, in-house PCBA and assembly capability, using the industry's most advanced silicone woven design and process, 20cm cable in length, no knots, super-soft, the HUB is easy to use in all scenarios: laptop, tablet, stand etc. Super-soft, 25000+ life cycles, to meet your daily carrying and office needs.
  • 100W Charging: Support up to 90W USB C pass-through charging via Type-C port to keep your laptop powered. 10W is reserved for other interface operations. No data and video function on the Type-C port.
  • 4K HDMI Display: The HDMI port supports media display at resolutions up to 4K 30Hz, keeping every incredible moment detailed and ultra vivid. Please note that the C port of the Host device needs to support video output.
  • Transfer Files in Seconds: Transfer files and from your laptop at speeds up to 10 Gbps with USB A 3.2 port. Extra 2 USB A 2.0 ports are perfectly for your keyboards and mouse.

The API spelling changes, but the client-propagation rule does not: use the transaction-bound tx supplied to the callback for each query that must participate. Match the callback syntax to the installed project version, and do not assume that an API rename makes ordinary service clients transaction-aware.

How can I find a query that is escaping the transaction?

Trace every database operation in the transaction’s call path to the client that executes it. A failure test that makes a later operation throw is useful only if you also verify that all earlier writes were issued through the same transaction-bound client.

  1. Identify the atomic unit. List the writes that should succeed or fail together, such as creating an order and recording its event.
  2. Follow each service call. Inspect the method that performs each write, including helpers further down the call chain. Look for calls through an injected default client such as this.prisma.
  3. Pass tx through every relevant method. Confirm that each method uses the supplied client for the write rather than silently falling back to the default.
  4. Exercise the failure path. Make a later database operation fail in a controlled scenario, then check whether the earlier related database writes remain. A surviving write indicates that at least one operation was not governed by the transaction as intended.

Do not treat a service call’s position in the callback as proof of participation. The useful code-review question is not “Was this method called inside the transaction?” but “Which client issued each query in this method?”

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which effects can’t a database transaction roll back?

A database transaction can govern database writes issued through its transaction-bound client; it does not undo an email sent, a job submitted to a queue, or another external side effect. If the callback later fails, the database may roll back while the already-triggered external action remains.

Also popular on Amazon
𝟒𝐏𝐚𝐜𝐤 𝐔𝐩𝐠𝐫𝐚𝐝𝐞𝐝 USB to USB C Adapter,Type-C Female to A Male Charger Converter for iPhone 18 Charger,iWatch Ultra SE 9 10,iPhone 17 Pro Max 16 15 14,Samsung S25,AirPods,iPad,Car,Xbox
  • 【Read before You Buy】 Note: This adapter is USB 2.0 version and cannot transmit HDM, VGA, or other video signals. Nevertheless, they are fully capable of charging devices,duplicating files, and can be seamlessly integrated with USB-C earphones, wireless network adapters, and SD card adapters.
  • 【Easy to Use and Safe】Thanks to modern manufacturing techniques, we've made these adapters sufficiently compact so that they can remain inserted in your device without noticeable protrusion or inconvenience. This means you don't have to constantly plug and unplug them, reducing the likelihood of wear and misalignment, and making them more convenient to carry around.
  • 【Reliable Quality】Engineered for enhanced durability, durable aluminum alloy shell material,get excellent wear resistance and heat dissipation,the male USB C and female USB connectors & the male USB and female USB C connectors are designed to be plugged and unplugged up to 20000 times. Provides data transfer, device charging, memory space expansion, and additional computer peripherals.
  • 【Think more for you】Do you need to connect a USB-C-enabled device to an odd device that only has USB-A ports? Then these USB-A male to USB-C female adapters are made for you.Simply insert the adapter into the USB-A port on the device, and you can instantly connect your USB-C device to the device that originally didn't have the correct connection port.
  • 【Trusted xiwxi Quality and Service】As a responsible brand seller, you will receive xiwxi's 12-month Quality assurance and lifetime friendly customer service, you're not just buying a product,you're investing in peace of mind with all-round quality and exceptional customer service.

Defer external effects until after the database transaction commits when that timing is acceptable. Where the database change and delivery of an external event must be coordinated more deliberately, use an explicitly designed transactional-outbox workflow. In either case, do not treat placing an email or queue call inside the transaction callback as making that external system part of the database transaction.

What should a transaction-capable service contract make clear?

A service method should make it apparent whether it can participate in a caller’s transaction and what happens when no transaction client is supplied. An optional tx parameter supports both use cases, but only if callers that need atomicity actually provide it and the method consistently uses it.

  • Participation: database operations that must roll back together use the same transaction-bound client.
  • Ergonomics: the method signature exposes transaction propagation instead of relying on an ambient-context assumption.
  • Failure behavior: when a later operation throws, related writes made through that client roll back with the transaction.
  • Version fit: the callback syntax matches the Prisma ORM version in the project.
  • Side-effect timing: email, queue, and other external work is handled after commit or through an explicitly designed coordination pattern.

These are not separate ways to make a transaction work. Together they describe a clear boundary: one transaction-bound client for related database writes, explicit handoff across service calls, and separate handling for effects the database cannot roll back.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can Prisma use ambient transaction context across service calls?

Not automatically for queries made through the ordinary default client. If a service must participate in a caller’s transaction, pass the transaction-bound client to it and have it issue the query through that client.

Can I pass Prisma.TransactionClient to a helper function?

Yes. The documented helper pattern is to accept the transaction client as a parameter and call the helper with the callback’s tx. That makes the helper’s database query use the caller’s transaction rather than starting a separate one.

Will an email sent in a transaction callback be canceled if the transaction fails?

No. Email delivery is an external side effect, not a database write governed by the database transaction. Defer it until after commit or coordinate it with an explicitly designed transactional-outbox workflow.

What does a transactional outbox solve?

It is an explicitly designed way to coordinate database changes with the later delivery of an external event. It is relevant when simply waiting until after commit is not enough for the application’s delivery requirements.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply. Prices as of December 6, 2026 10:01 am GMT.