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

Optional-defined fields with validation rules are saved in the storage and can violate Response Validation #1051

Open
oxisto opened this issue Apr 4, 2023 Discussed in #1010 · 1 comment

Comments

@oxisto
Copy link
Member

oxisto commented Apr 4, 2023

Discussed in #1010

Originally posted by lebogg March 14, 2023
Even when we use optional for a proto field (see example below), the storage will save the respective tuple with a zero value of this field (e.g. empty string in the raw field). When we then call ListEvidences, e.g., we (in theory) can have a validation error since we have filled the field raw with empty string but now validation rules apply (min length 1 in this example). Thus, we would get errors when we check these evidences with corresponding validation methods. e.g. with the validation on the response (func (m *ListEvidencesResponse) Validate()). This currently happens in the new tests of #999, where we use the response validation method.

The question is: Do we just ignore it; adjust the .proto files; or adjust storage operations to make nil entries if that is even possible.

Example:

optional string raw = 5 [ (validate.rules).string.min_len = 1 ];

This seems strange because the database can handle NULL fields, so sin this case null/nil should be stored in the DB instead of "". Maybe we need to set a different "default value" (see https://gorm.io/docs/models.html#Fields-Tags, tag default).

@oxisto
Copy link
Member Author

oxisto commented Jun 20, 2023

We should check, whether nullable/optional fields are really stored as "null" in the database (and not as an empty string for example)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant