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
Preventing update/insert of read-only fields in a table by user (#1596)
## Why make this change?
There are certain type of columns in databases which cannot be provided
a value (not even null value) for by the user. Eg. in MsSql tables, we
cannot provide values for columns that are computed base on other
columns in the table or have a datatype of timestamp/rowversion.
Similarly for PgSql,/MySql we cannot provide a value for generated
columns. This PR prevents DAB from allowing user to attempt an
update/insert of such columns. The way DAB will do this is by collecting
metadata about columns during the startup phase and populate the
`IsReadOnly` property of the `ColumnDefinition` of each column in the
table. More details about the specifics can be found on the linked
issues for MsSql(#1453),
PgSql(#1584),
MySql(#1583).
**NOTE:** The columns which are autogenerated are also considered as
read-only columns irrespective of the database flavor
(MsSql/PgSql/MySql).
## What is this change?
- Added a new boolean property `IsReadOnly` to `ColumnDefinition` class
which if true, will indicate that the column is read-only, i.e. it
cannot be provided a value for (via INSERT/UPDATE).
- Added a new method `GetQueryToGetReadOnlyColumns()` to
`IQueryBuilder.cs` class which will have its overridden implementation
in Pg/My/MsSql. This method will return the query that will fetch the
metadata about the whether a column is read-only.
- Added validations to `RequestValidator.cs` class which will ensure
that no read-only column is present the request body either for update
(via `Upsert`/`UpsertIncremental`/`Update`/`UpdateIncremental`) or
insert operations.
- Added similar validations to
`SqlInsertQueryStructure.cs`/`SqlUpdateQueryStructure.cs`- classes as
the request validation stage is not a part of the codeflow for GQL
requests.
- Via GQL, value for a read-only field cannot be provided. This will be
enabled by adding the `AutoGeneratedDirectiveType` when a column is
read-only. Previous this directive was only added for autogenerated
fields (which is a subset of read-only fields).
## Implemented Behaviors:
1. `When a read-only field is included in the request body for
mutation:` This is a bad request as we cannot provide values for
read-only fields. We will throw an exception no matter what operation is
being executed (`PUT/PATCH/POST via REST). For create/update via GQL`,
we would see a warning in the BCP UI for read-only fields as well that
the field is not valid for mutation (just like we see currently for
autogen fields).
2. `When a read-only field is excluded from the request body for
mutation`: This is a valid scenario. In this case (`for PUT/PATCH
operations via REST`), we won't NULL out the field's value but let the
responsibility on the database to deal with it. For other operations, we
really don't need to do anything as the field is not present in the
request body.
## How was this tested?
- [x] Integration Tests
---------
Co-authored-by: Sean Leonard <[email protected]>
0 commit comments