Commit b0e2e90
committed
fix(model): guard the scope dereference in validatesUniquenessOf
`validatesUniquenessOf(property="x", scope="y")` threw
Component [MyModel] has no accessible Member with name [y]
whenever `y` had never been assigned — out of a method whose entire job is to return a
validation result. A caller that correctly wraps `save()` in an `if` still got an exception,
and it surfaced as a 500.
`$buildWhereClausePart()` read `this[arguments.property]` with no existence guard. That is
easy to hit because absent and empty are different states here: `$setDefaultValues()` only
seeds properties that have an explicit `property()` mapping, so a column with a
database-level default but no mapping is missing from a `new()`-ed object rather than
present-and-blank. The `scope=` in the model source looks fine; nothing in it hints that the
property will be absent at validation time.
Only scopes were exposed. The validated property itself cannot reach this code absent —
`$shouldInvokeValidation()` returns false when it is missing from the object — which is why
the split went unnoticed: "unset" and "set to empty" produced an exception and a validation
result respectively, for the same logical state.
An absent scope property is now treated as blank, so both states take the identical path,
including the existing conversion of an empty numeric scope to `IS NULL`. The guard mirrors
`validationTypeForProperty()` and `key()` in the same layer, which already read optional
properties this way.
Red-first: 945 pass / 0 fail / 2 errors, both errors being the reported message verbatim
against the existing `CombiKey` fixture (`validatesUniquenessOf(property="id1",
scope="id2")`).
Verification, lucee7 + sqlite, full core suite:
develop ab901cf 4732 pass / 0 fail / 0 error
this branch 4734 pass / 0 fail / 0 error
Exactly +2, the new specs.
Closes #3350
Signed-off-by: Peter Amiri <peter@alurium.com>1 parent ab901cf commit b0e2e90
4 files changed
Lines changed: 38 additions & 78 deletions
File tree
- changelog.d
- public/testbox/system/stubs
- vendor/wheels
- model
- tests/specs/model
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 0 additions & 77 deletions
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
783 | 783 | | |
784 | 784 | | |
785 | 785 | | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
786 | 796 | | |
787 | | - | |
| 797 | + | |
788 | 798 | | |
789 | 799 | | |
790 | 800 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1015 | 1015 | | |
1016 | 1016 | | |
1017 | 1017 | | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
1018 | 1044 | | |
1019 | 1045 | | |
1020 | 1046 | | |
| |||
0 commit comments