You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sequelize/sequelize#15598 tightened up the handling of JSONB values in WHERE clauses for the better. However, it subtly changed how Model.create works with nullable JSONB columns. Before, creating a model with such a column explicitly set to null would make the column null:
A workaround is to leave out the value (or pass undefined) when you mean to leave the column as null, as that'll omit it from the INSERT, leaving it as null:
This change in behavior doesn't seem to be called out in the PR description for sequelize/sequelize#15598 or in #417, so I assume it's a regression. The spirit of that change was to tighten up how JSONB columns are handled, where it now forces you to actively use { [Op.is]: null } or { [Op.eq]: null } in WHERE clauses, which is great. Equivalent to that you should probably be forced to select between populating a column with null or a JSONB null value. Until we can get there, I'd argue that the semantics shouldn't change.
No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
The text was updated successfully, but these errors were encountered:
papandreou
changed the title
footgun/regression: Creating a new model with a jsonb column set to null inserts a JSONB null value rather than leaving the column as null
footgun/regression: Creating a new model with a JSONB column set to null inserts a JSONB null value rather than leaving the column as nullSep 12, 2023
Thanks for clarifying! I'm worried that this will cause problems for people who upgrade to Sequelize 7, because they might not immediately realize that the behavior is changing? Also, I think the old behavior is less surprising, as that's what passing null does for all other nullable columns?
Issue Creation Checklist
Bug Description
sequelize/sequelize#15598 tightened up the handling of JSONB values in
WHERE
clauses for the better. However, it subtly changed howModel.create
works with nullableJSONB
columns. Before, creating a model with such a column explicitly set tonull
would make the columnnull
:After sequelize/sequelize#15598 was merged,
'null'
is inserted, which makes the column contain a JSONB null value:A workaround is to leave out the value (or pass
undefined
) when you mean to leave the column asnull
, as that'll omit it from theINSERT
, leaving it asnull
:This change in behavior doesn't seem to be called out in the PR description for sequelize/sequelize#15598 or in #417, so I assume it's a regression. The spirit of that change was to tighten up how
JSONB
columns are handled, where it now forces you to actively use{ [Op.is]: null }
or{ [Op.eq]: null }
inWHERE
clauses, which is great. Equivalent to that you should probably be forced to select between populating a column withnull
or a JSONBnull
value. Until we can get there, I'd argue that the semantics shouldn't change.Reproducible Example
What do you expect to happen?
That Sequelize populates the
jsonbColumn
column withnull
.What is actually happening?
It gets populated with a JSONB
null
value.Environment
Would you be willing to resolve this issue by submitting a Pull Request?
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
The text was updated successfully, but these errors were encountered: