fix(RT): correct restricting null columns (#11123)

# Which Problems Are Solved

`IS NULL` and `IS NOT NULL` conditions were incorrectly marked as
restricting columns,
and currently fails unit tests. The restricting columns are mostly used
to ensure single row selection during DELETE and UPDATE . When a `IS NOT
NULL` condition is passed, the filter may (unintentionally) apply to all
rows, while still allowing the query to execute.

Settings and other repositories (still to be done) have unified tables
for instance-level settings and organization-level settings. In those
cases the organization ID may be null or have a value. The unique
condition is a compound of multiple columns, in which case `IS NULL` is
valid as part of the other restricting columns.

# How the Problems Are Solved

In order to prevent unsafe usage of null related filters and not break
settings:

- null conditions are no longer considered restricting columns
- A function to force the restricting column state on a condition is
provided
- The settings unique condition function forces restricting column state
on the returned condition.

# Additional Changes

- add `backend/v3` to the NX build.

# Additional Context

- [pipeline
failures](https://github.com/zitadel/zitadel/actions/runs/19852295780/job/56881654340?pr=11115#step:13:3197)

---------

Co-authored-by: Elio Bischof <[email protected]>
This commit is contained in:
Tim Möhlmann
2025-12-03 16:15:49 +00:00
committed by GitHub
co-authored by Elio Bischof
parent 96fffd9829
commit b4732579cb
7 changed files with 99 additions and 64 deletions
+10 -10
View File
@@ -174,13 +174,13 @@ func TestWrite(t *testing.T) {
func TestIsRestrictingColumn(t *testing.T) {
for _, test := range []struct {
name string
col Column
arg Column
cond Condition
want bool
}{
{
name: "and with restricting column",
col: NewColumn("table", "column1"),
arg: NewColumn("table", "column1"),
cond: And(
NewColumnCondition(NewColumn("table", "column1"), NewColumn("other_table", "column2")),
NewColumnCondition(NewColumn("table", "column1"), NewColumn("other_table", "column3")),
@@ -189,7 +189,7 @@ func TestIsRestrictingColumn(t *testing.T) {
},
{
name: "and without restricting column",
col: NewColumn("table", "column1"),
arg: NewColumn("table", "column1"),
cond: And(
NewColumnCondition(NewColumn("table", "column2"), NewColumn("other_table", "column3")),
IsNull(NewColumn("table", "column4")),
@@ -199,7 +199,7 @@ func TestIsRestrictingColumn(t *testing.T) {
},
{
name: "or with restricting column",
col: NewColumn("table", "column1"),
arg: NewColumn("table", "column1"),
cond: Or(
NewColumnCondition(NewColumn("table", "column1"), NewColumn("other_table", "column2")),
NewColumnCondition(NewColumn("table", "column1"), NewColumn("other_table", "column3")),
@@ -208,7 +208,7 @@ func TestIsRestrictingColumn(t *testing.T) {
},
{
name: "or without restricting column",
col: NewColumn("table", "column1"),
arg: NewColumn("table", "column1"),
cond: Or(
NewColumnCondition(NewColumn("table", "column1"), NewColumn("other_table", "column3")),
IsNotNull(NewColumn("table", "column4")),
@@ -218,19 +218,19 @@ func TestIsRestrictingColumn(t *testing.T) {
},
{
name: "is null never restricts",
col: NewColumn("table", "column1"),
arg: NewColumn("table", "column1"),
cond: IsNull(NewColumn("table", "column1")),
want: false,
},
{
name: "is not null never restricts",
col: NewColumn("table", "column1"),
arg: NewColumn("table", "column1"),
cond: IsNotNull(NewColumn("table", "column1")),
want: false,
},
{
name: "exists with restricting column",
col: NewColumn("table", "column1"),
arg: NewColumn("table", "column1"),
cond: Exists("table", And(
NewColumnCondition(NewColumn("table", "column1"), NewColumn("other_table", "column2")),
NewColumnCondition(NewColumn("table", "column1"), NewColumn("other_table", "column3")),
@@ -239,7 +239,7 @@ func TestIsRestrictingColumn(t *testing.T) {
},
{
name: "exists without restricting column",
col: NewColumn("table", "column1"),
arg: NewColumn("table", "column1"),
cond: Exists("table", Or(
NewColumnCondition(NewColumn("table", "column1"), NewColumn("other_table", "column3")),
IsNotNull(NewColumn("table", "column4")),
@@ -249,7 +249,7 @@ func TestIsRestrictingColumn(t *testing.T) {
},
} {
t.Run(test.name, func(t *testing.T) {
isRestricting := test.cond.IsRestrictingColumn(test.col)
isRestricting := test.cond.IsRestrictingColumn(test.arg)
assert.Equal(t, test.want, isRestricting)
})
}