Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Conversation

sapphire008
Copy link
Contributor

@sapphire008 sapphire008 commented Mar 31, 2024

What kind of change does this PR introduce?

Feature / Bug Fix: adding the default_to_null parameter for upsert and insert methods as presented in both JavaScript and Dart/Flutter version of the client.

What is the current behavior?

When doing bulk insert/upsert of rows into the Postgresql table, the missing fields are default to Nulls instead of using the default value of the column. The parameter default_to_null allows the user to use default values from the column definition, instead of using Nulls. But this parameter is currently not exposed in the Python client, though they are available in both JavaScript and Dart/Flutter clients.

What is the new behavior?

When default_to_null = True (default value), the current behavior withholds, where missing fields from the json payload will be inserted using Null.

When setting default_to_null = False AND user is performing bulk insert / upsert (i.e. json payload is a list of dictionary), the rows will be inserted with default values from the table/column definitions, rather than using Nulls.

This is done by setting two things in the PostgREST call:

  • Adding columns="column1","column2" in the query parameter of the POST call
  • Adding Prefer: missing=default in the header of the POST call.

The documentation from both Dart/Flutter and Javascript has indicated that setting default_to_null = False only applies to bulk insertion/upsersion: https://supabase.com/docs/reference/javascript/insert. Therefore, to update a single record, the user can wrap the json/dict as a list, i.e. [insert_dict].

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @sapphire008 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟡 Security: 1 issue found
  • 🟡 Testing: 6 issues found
  • 🟡 Complexity: 1 issue found
  • 🟢 Docstrings: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@sapphire008
Copy link
Contributor Author

Merged the newest change from master that reverted codecov-action version. Should be ready to try again with CI.

@sapphire008
Copy link
Contributor Author

Fixed linting issues using pre-commit.

@codecov
Copy link

codecov bot commented Apr 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.91%. Comparing base (b858685) to head (485eab9).
Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #398      +/-   ##
==========================================
+ Coverage   95.72%   95.91%   +0.18%     
==========================================
  Files          28       28              
  Lines        1639     1715      +76     
==========================================
+ Hits         1569     1645      +76     
  Misses         70       70              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sapphire008
Copy link
Contributor Author

@J0 @olirice @anand2312 Any comments? Is it ready for merging?

Copy link
Contributor

@silentworks silentworks left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution.

@silentworks silentworks merged commit ae5f80a into supabase:master Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants