Skip to content

fix(qe): Change Array(None) to return Null value. #5228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

igort99
Copy link

@igort99 igort99 commented Mar 5, 2025

Description

In PostgreSQL, a nullable array column can hold either a null value or an empty array ({}), and these are semantically different. Previously, Prisma treated both cases as an empty array. This fix ensures that when the database returns a null for a nullable array column, Prisma correctly returns a null instead of an empty list.

Related Issue

Changes Made

  • Updated the conversion logic for list fields in the SQL row conversion. The branch that previously matched any null value and returned an empty list has been modified (or removed) so that a SQL null is properly recognized.

Screenshots (if applicable)

Before the fix, the following query would return an empty array for a null column:

CREATE OR REPLACE TABLE nullable_array ( arr text[] );
INSERT INTO nullable_array VALUES (null);

@igort99 igort99 requested a review from a team as a code owner March 5, 2025 20:30
@igort99 igort99 requested review from FGoessler and removed request for a team March 5, 2025 20:30
@CLAassistant
Copy link

CLAassistant commented Mar 5, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

codspeed-hq bot commented Mar 6, 2025

CodSpeed Performance Report

Merging #5228 will not alter performance

Comparing igort99:fix/null-array-returned-as-empty (58949d1) with main (d8cf42b)

Summary

✅ 11 untouched benchmarks

Copy link
Member

@aqrln aqrln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening the PR. As you can see from the tests you had to change, this is a breaking change that will affect the client API and users' application code. If you can scope this to raw queries only, then it would be a bugfix we could merge.

As for the changes you've made, I'd love to remove these conversions and I'm very much not a fan of the current behaviour. However, your changes are insufficient: it is also necessary to update the PSL to allow the syntax for defining nullable lists, update the client type generation and query validation, and update the tests on the client side. And, as I said, it can only land in a major release (i.e. Prisma 7).

@igort99
Copy link
Author

igort99 commented Mar 11, 2025

@aqrln Thanks for comment. While working on this, I realized these changes would be breaking as many users depend on this behaviour, but I continued so I could get feedback and confirmation. I will try to scope this to raw queries only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants