Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: @set expression schema validations #1273

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,313 changes: 1,313 additions & 0 deletions schema/testdata/proto_set_attribute_lhs_within_write_scope/proto.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
model Post {
fields {
name Text?
published Boolean?
identity Identity?
publisher Publisher?
}

actions {
create nestedData1() with (
publisher.country.id,
publisher.departments.name,
publisher.departments.number,
) {
@set(post.publisher.departments.head.id = ctx.identity.person.id)
}
create nestedData2() with (name) {
@set(post.publisher.id = ctx.identity.publisher.id)
}
create nestedData3() with (
publisher.country.id,
publisher.departments.name,
publisher.departments.number,
) {
@set(post.publisher.name = "someName")
}
create nestedData4() with (
publisher.country.id,
publisher.departments.name,
publisher.departments.number,
) {
@set(post.name = "some name")
}
create nestedData5() with (name) {
@set(post.publisher = ctx.identity.publisher)
}
create nestedData6() with (publisher.country.id) {
@set(post.publisher.name = "someName")
}
create nestedData7() with (
publisher.country.name,
publisher.departments.name,
publisher.departments.number,
) {
@set(post.publisher.country.publishersCount = 1)
}
create nestedData8() with (
publisher.country.id,
publisher.departments.name,
publisher.departments.number,
) {
@set(post.publisher.departments.head = ctx.identity.person)
}
}
}

model Publisher {
fields {
name Text
owner Person
departments Department[]
country Country
admin Identity @unique
}
}

model Department {
fields {
publisher Publisher
head Person?
name Text
number Text
}
}

model Country {
fields {
name Text?
publishersCount Number?
}
}

model Person {
fields {
name Text
identity Identity @unique
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
"code": "E060",
"pos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 142,
"offset": 163,
"line": 9,
"column": 18
},
"endPos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 160,
"offset": 181,
"line": 9,
"column": 36
}
},
{
"message": "name cannot be null",
"message": "country cannot be null",
"hint": "You cannot evaluate a field against null unless it is defined as optional",
"code": "E060",
"pos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 179,
"offset": 200,
"line": 10,
"column": 18
},
"endPos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 197,
"offset": 230,
"line": 10,
"column": 36
"column": 48
}
},
{
Expand All @@ -40,15 +40,15 @@
"code": "E060",
"pos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 216,
"line": 11,
"column": 18
"offset": 348,
"line": 15,
"column": 20
},
"endPos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 243,
"line": 11,
"column": 45
"offset": 367,
"line": 15,
"column": 39
}
},
{
Expand All @@ -57,13 +57,13 @@
"code": "E060",
"pos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 361,
"offset": 388,
"line": 16,
"column": 20
},
"endPos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 380,
"offset": 407,
"line": 16,
"column": 39
}
Expand All @@ -74,31 +74,14 @@
"code": "E060",
"pos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 401,
"offset": 428,
"line": 17,
"column": 20
},
"endPos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 420,
"offset": 456,
"line": 17,
"column": 39
}
},
{
"message": "name cannot be null",
"hint": "You cannot evaluate a field against null unless it is defined as optional",
"code": "E060",
"pos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 441,
"line": 18,
"column": 20
},
"endPos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 469,
"line": 18,
"column": 48
}
},
Expand All @@ -108,14 +91,14 @@
"code": "E060",
"pos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 281,
"line": 12,
"offset": 268,
"line": 11,
"column": 37
},
"endPos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 300,
"line": 12,
"offset": 287,
"line": 11,
"column": 56
}
},
Expand All @@ -125,14 +108,14 @@
"code": "E060",
"pos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 507,
"line": 19,
"offset": 494,
"line": 18,
"column": 37
},
"endPos": {
"filename": "testdata/validation_expression_null_non_optional_field/schema.keel",
"offset": 526,
"line": 19,
"offset": 513,
"line": 18,
"column": 56
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ model Person {
}

actions {
create createPerson() {
create createPerson() with (employer.name) {
@set(person.name = null)
@set(null = person.name)
@set(person.employer.name = null)
@set(person.employer.country = null)
@permission(expression: person.name != null)
}

Expand All @@ -24,6 +23,7 @@ model Person {
model Company {
fields {
name Text
country Text
employees Person[]
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@
"line": 13,
"column": 37
}
},
{
"message": "The @set attribute cannot be a logical condition and must express an assignment",
"hint": "For example, assign a value to a field on this model with @set(profile.isActive = true)",
"code": "AttributeArgumentError",
"pos": {
"filename": "testdata/validation_operation_set_expression_forbidden_operator/schema.keel",
"offset": 230,
"line": 13,
"column": 18
},
"endPos": {
"filename": "testdata/validation_operation_set_expression_forbidden_operator/schema.keel",
"offset": 262,
"line": 13,
"column": 50
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"errors": [
{
"message": "Value-only conditions such as 'profile.identity' not permitted on @set",
"hint": "Please assign a value. Did you mean 'profile.identity = xxx'?",
"code": "E023",
"message": "The @set attribute cannot be a value condition and must express an assignment",
"hint": "For example, assign a value to a field on this model with @set(profile.isActive = true)",
"code": "AttributeArgumentError",
"pos": {
"filename": "testdata/validation_operation_set_forbidden_value_expression/schema.keel",
"offset": 229,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"code": "E031",
"pos": {
"filename": "testdata/validation_set_attribute_backlink_repeated_fields/schema.keel",
"offset": 201,
"line": 10,
"offset": 246,
"line": 11,
"column": 40
},
"endPos": {
"filename": "testdata/validation_set_attribute_backlink_repeated_fields/schema.keel",
"offset": 202,
"line": 10,
"offset": 247,
"line": 11,
"column": 41
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
model Record {
fields {
name Text
owner User?
parent Record?
children Record[]
}

actions {
create createRecordWithChildren() {
create createRecordWithChildren() with (name, children.name) {
@set(record.children.owner = ctx.identity.user.records.owner)
}
}
Expand Down
Loading