-
-
Notifications
You must be signed in to change notification settings - Fork 64
Upsert / Insert with default_to_null boolean argument #398
Upsert / Insert with default_to_null boolean argument #398
Conversation
There was a problem hiding this 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
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
…tgrest-py into upsert-defaultToNull
Merged the newest change from master that reverted |
Fixed linting issues using pre-commit. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
@J0 @olirice @anand2312 Any comments? Is it ready for merging? |
There was a problem hiding this 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.
What kind of change does this PR introduce?
Feature / Bug Fix: adding the
default_to_null
parameter forupsert
andinsert
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:
columns="column1","column2"
in the query parameter of the POST callPrefer: 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]
.