🌟 **Help us spread the word about Prisma by starring the repo or [tweeting](https://twitter.com/intent/tweet?text=Check%20out%20the%20latest%20prisma%20release%20v4.4.0%20%F0%9F%9A%80%0D%0A%0D%0Ahttps://github.com/prisma/prisma/releases/tag/4.4.0) about the release.** 🌟
Major improvements
General improvements
In the last sprint, we focused our efforts on squashing as many bugs as we could. You can find the full list of improvements and bug fixes in the **Fixes and improvements** section below.
Some of the improvements we made include but are not limited to:
- Improved optimistic concurrency control ([GitHub issue](https://github.com/prisma/prisma/issues/8612))
- Improved decimal precision
- Improved handling of big amounts of prepared statement placeholders:
Databases impose limits when they hit a specific number, and when a query (either generated by Prisma Client or provided by the user directly as a raw query) hits it some users ran into a misleading `Can't reach database server` error message ([GitHub issue](https://github.com/prisma/prisma/issues/8832)). The error message will now be more useful (`P2035` error code), and Prisma Client should not cause these errors anymore.
If you notice any regression, please make sure to [create a GitHub issue](https://github.com/prisma/prisma/issues/new?assignees=&labels=kind%2Fbug&template=bug_report.yml). We touched a lot of code in this sprint, and even though we are confident in our tests, something might have slipped through the cracks. We'd like to fix the regressions as soon as possible.
`isolationLevel` for sequential transaction operations
In version `4.2.0`, we added support for setting transaction isolation levels for interactive transactions (Preview). You can now define isolation levels for sequential transaction operations: `prisma.$transaction([])`.
Isolation levels describe different types of trade-offs between isolation and performance that databases can make when processing transactions. Isolation levels determine what types of data leaking can occur between transactions or what data anomalies can occur.
To set the transaction isolation level, use the `isolationLevel` option in the second parameter of the API. For example:
ts
await prisma.$transaction(
[
// sequential operations
prisma.user.create({ data: {/** args */ } }),
prisma.post.create({ data: {/** args */ } })
],
{
isolationLevel: Prisma.TransactionIsolationLevel.Serializable
}
)
Prisma Client supports the following isolation levels if they're available in your database provider:
- `ReadCommitted`
- `ReadUncommitted`
- `RepeatableRead`
- `Serializable`
- `Snapshot`
Learn more about it in our [documentation](https://www.prisma.io/docs/concepts/components/prisma-client/transactions#sequential-prisma-client-operations).
New `P2034` error code for transaction conflicts or deadlocks
When using certain isolation levels, it is expected that a transaction can fail due to a write conflict or a deadlock, throwing an error. One way to solve these cases is by retrying the transaction.
To make this easier, we're introducing a new `PrismaClientKnownRequestError` with the error code `P2034`: "Transaction failed due to a write conflict or a deadlock. Please retry your transaction". You can programmatically catch the error and retry the transaction. Here's an example showing how you can retry a transaction:
ts
import { Prisma, PrismaClient } from 'prisma/client'
const prisma = new PrismaClient()
async function main() {
const MAX_RETRIES = 5
let retries = 0;
let result;
while (retries < MAX_RETRIES) {
try {
result = await prisma.$transaction(
[
prisma.user.deleteMany({ where: { /** args */ } }),
prisma.post.createMany({ data: { /** args */ } })
],
{
isolationLevel: Prisma.TransactionIsolationLevel.Serializable
}
)
} catch (error) {
if (error.code === 'P2034') {
retries++
continue
}
throw error
}
}
}
Fixes and improvements
Prisma Client
- [Wrong types for fluent API when used along with `rejectOnNotFound`](https://github.com/prisma/prisma/issues/5715)
- [Precision issue when persisting Decimal.js objects](https://github.com/prisma/prisma/issues/5925)
- [Decimals lose precision (postgres)](https://github.com/prisma/prisma/issues/6852)
- [Weird behavior with "in:" clause on a findMany() with orderBy + take](https://github.com/prisma/prisma/issues/7143)
- [decimal lose precision digits to postgres](https://github.com/prisma/prisma/issues/8160)
- [`updateMany()` causes lost-updates](https://github.com/prisma/prisma/issues/8612)
- [Error: P1001: Can't reach database server when including large table](https://github.com/prisma/prisma/issues/8878)
- [Client shows contains filter on uuid data type despite not being a valid operation](https://github.com/prisma/prisma/issues/9007)
- [A model with relation to another model via non-null foreign key has nullable type](https://github.com/prisma/prisma/issues/9138)
- [Validation error when inserting data of type `List<String | DateTime>` into field of type `List<String>`](https://github.com/prisma/prisma/issues/9248)
- [Can't reach database server when doing a large findMany query](https://github.com/prisma/prisma/issues/9275)
- [Maximum call stack size exceeded when creating huge amount of related rows ](https://github.com/prisma/prisma/issues/9372)
- [Unique constraint failed during `$transaction([deleteMany, createMany])`](https://github.com/prisma/prisma/issues/9678)
- [update will break atomicity](https://github.com/prisma/prisma/issues/9798)
- [Nested self referential orderby not working](https://github.com/prisma/prisma/issues/9929)
- [MySQL: Optimistic Concurrency Control doesn't work with UpdateMany](https://github.com/prisma/prisma/issues/10207)
- [Wrong type when retrieving multiple related records using fluent API](https://github.com/prisma/prisma/issues/10656)
- [Fluent API produces runtime error](https://github.com/prisma/prisma/issues/10687)
- [Column 'orderby_.....' in on clause is ambiguous](https://github.com/prisma/prisma/issues/10735)
- [[PostgreSQL] Cannot create or update row with large Decimal value within `numeric` range](https://github.com/prisma/prisma/issues/11464)
- [Failed transactions trigger multipleResolves](https://github.com/prisma/prisma/issues/11740)
- [`The provided database string is invalid. Unable to parse URL. in database URL.` on invalid (?) connection string](https://github.com/prisma/prisma/issues/11883)
- [relation query fails when thousands of records](https://github.com/prisma/prisma/issues/11950)
- [Unable to query records with certain values](https://github.com/prisma/prisma/issues/11984)
- [orderBy using self-referential relation in a nested relation fails with "table name \"TableName\" specified more than once"](https://github.com/prisma/prisma/issues/12003)
- [updatedAt does not work with default ](https://github.com/prisma/prisma/issues/12189)
- [Prisma silently misses nested elements on MariaDB when it triggers a huge IN clause](https://github.com/prisma/prisma/issues/12338)
- [`createdAt default(now())` and `updatedAt updatedAt` get different times on row creation](https://github.com/prisma/prisma/issues/12572)
- [Interactive Transactions: fatal when throwing string instead of Error() since 3.10.0](https://github.com/prisma/prisma/issues/12663)
- [Prisma MongoDB can not search for field with value `$foo`](https://github.com/prisma/prisma/issues/13089)
- [groupBy crashes when using enums](https://github.com/prisma/prisma/issues/13097)
- [MySQL DECIMAL(X, 5) returns incorrect precision. ](https://github.com/prisma/prisma/issues/13156)
- ["Join" performance: (Not so) huge data set throws an error](https://github.com/prisma/prisma/issues/13306)
- [`Error: The provided database string is invalid. Unable to parse URL. in database URL.` ](https://github.com/prisma/prisma/issues/13388)
- [[mongoDB] `findRaw` does not work within an `interactiveTransaction`](https://github.com/prisma/prisma/issues/13405)
- [Filters max size is exceeded](https://github.com/prisma/prisma/issues/13457)
- [Prisma fails on Postgres query with findMany](https://github.com/prisma/prisma/issues/13704)
- [Update Restrict failed on prisma referentialIntegrity](https://github.com/prisma/prisma/issues/13766)
- [invalid character in $let in $lookup pipeline when using cursor and order by query](https://github.com/prisma/prisma/issues/14001)
- [Find many returns empty array or null](https://github.com/prisma/prisma/issues/14019)
- [Once instance has previously been poisoned](https://github.com/prisma/prisma/issues/14130)
- [Sanitize error snapshots in new test setup](https://github.com/prisma/prisma/issues/14321)
- [The findMany query fails silently when the array length passed through IN parameter exceeds 999](https://github.com/prisma/prisma/issues/14539)
- [mongodb cannot use $runCommand Raw in transaction](https://github.com/prisma/prisma/issues/14543)
- [`parent result: Some(ManyRecords { records: [Record { values: [Int(3), Int(1), DateTime(2022-08-08T12:27:55.310+00:00)], parent_id: None }], field_names: ["id", "userId", "createdAt"] }), relation: Relation { name: "post", model_a_name: "Comment", model_b_name: "Post", model_a: OnceCell((Weak)), model_b: OnceCell((Weak)), field_a: OnceCell((Weak)), field_b: OnceCell((Weak)), manifestation: Inline(InlineRelation { in_table_of_model_name: "Comment" }), internal_data_model: "InternalDataModelWeakRef" }`](https://github.com/prisma/prisma/issues/14696)
- [Given exponent overflowing the maximum accepted scale (255).: TryFromIntError(())](https://github.com/prisma/prisma/issues/14703)
- [Once instance has previously been poisoned](https://github.com/prisma/prisma/issues/14864)
- [sqlite:cuid():called `Result::unwrap()` on an `Err` value: FingerprintError("Could not retrieve hostname")](https://github.com/prisma/prisma/issues/14870)
- [Calling `findUnique` concurrently with a `DateTime` column causes it to return `null`](https://github.com/prisma/prisma/issues/14954)
- [Maximum Call Stack Size Exceeded When Inserting large Array Object](https://github.com/prisma/prisma/issues/15033)
- [Prisma Client is incompatible with TypeScript 4.8](https://github.com/prisma/prisma/issues/15041)
- [This is a non-recoverable error: When creating Item with nested query](https://github.com/prisma/prisma/issues/15064)
- [Given exponent overflowing the maximum accepted scale (255).: TryFromIntError(())](https://github.com/prisma/prisma/issues/15079)
- [Prisma 4.3.0 takes 100x more time to generate types](https://github.com/prisma/prisma/issues/15109)
- [Tracing: `prisma:engine` spans always get sampled when using probability based samplers](https://github.com/prisma/prisma/issues/15129)
- [Datasource providers in `prisma init` is listing wrong values](https://github.com/prisma/prisma/issues/15149)
- [Disconnect with large queries](https://github.com/prisma/prisma/issues/15168)
- [`N/A` error and message with large raw queries](https://github.com/prisma/prisma/issues/15169)
- [only one updatedAt is filled by the QE although multiple are accepted in the schema](https://github.com/prisma/prisma/issues/15176)
- [Insert fails if a table has a space in the name of the primary key](https://github.com/prisma/prisma/issues/15177)
- [Bug with throwing formatted errors](https://github.com/prisma/prisma/issues/15180)
- [called `Option::unwrap()` on a `None` value](https://github.com/prisma/prisma/issues/15204)
- [Upsert error on MySQL: `Query ... is required to return data, but found no record(s)`](https://github.com/prisma/prisma/issues/15264)
- [Add tests for mongodb's `findRaw`, `aggregateRaw` and `runCommandRaw` in sequential transactions](https://github.com/prisma/prisma/issues/15532)
Prisma
- [sqlite: show better error when a permission denied error occurs](https://github.com/prisma/prisma/issues/13991)
- [Prisma v4 breaks support for empty `dbgenerated()` - invalid migration created with no schema change](https://github.com/prisma/prisma/issues/14799)
- [Binary engine: `$disconnect` never returns if engine failed to start](https://github.com/prisma/prisma/issues/15548)
Prisma Migrate
- [PostGis views access error](https://github.com/prisma/prisma/issues/15361)
Prisma Studio
- [Client error "Can't reach database" for some tables not others](https://github.com/prisma/studio/issues/853)
Credits
Huge thanks to abenhamdine, miguelgargallo, Clansty, panoplied, MEnnabah, drzamich, AndrewSouthpaw, kt3k for helping!
💼 We're hiring!
If you're interested in joining our growing team to help empower developers to build data-intensive applications, Prisma is the place for you.
We're looking for a [Developer Advocate (Frontend / Fullstack)](https://grnh.se/894b275b2us) and [Back-end Engineer: Prisma Data Platform](https://grnh.se/45afe7982us).
Feel free to read the job descriptions and apply using the links provided.
Prisma Data Platform
We're working on the Prisma Data Platform — a collaborative environment for connecting apps to databases. It includes the:
- **Data Browser** for navigating, editing, and querying data
- **Data Proxy** for your database's persistent, reliable, and scalable connection pooling.
- **Query Console** for experimenting with queries
[Try it out](https://cloud.prisma.io/) and let us know what you think!
📺 Join us for another "What's new in Prisma" livestream
Learn about the latest release and other news from the Prisma community by joining us for another ["What's new in Prisma"](https://youtu.be/b1XXWPRSIjQ) livestream.
The stream takes place [on YouTube](https://youtu.be/b1XXWPRSIjQ) on **Thursday, September 29** at **5 pm Berlin | 8 am San Francisco**.