Skip to content

Commit e807f38

Browse files
authored
fix: panic when using autotruncate on a null value (#268)
* fix: panic when using autotruncate on a null value * fix: venom test
1 parent 277062d commit e807f38

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

CHANGELOG.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ Types of changes
1616

1717
## [2.7.1]
1818

19-
- `Fixed` panic during push on Oracle database with a `null` column value.
20-
- `Fixed` issue with SQL queries involving limit orders in SQL Server database.
19+
- `Fixed` panic during push on Oracle database with a `null` column value
20+
- `Fixed` issue with SQL queries involving limit orders in SQL Server database
21+
- `Fixed` panic when using autotruncate on a null value
2122

2223
## [2.7.0]
2324

24-
- `Added` columns information and export type using the `lino table extract` command, columns and keys organized according to the database order.
25-
- `Added` flag `--only-tables` to `lino table extract` command. This flag allows for the extraction of table information exclusively, excluding columns. It has been included to maintain the previous behavior.
26-
- `Added` flag `--with-db-infos` to `lino table extract` command. This flag enables the extraction of information regarding column types, length, size, and precision if the column has been configured with these specifications.
27-
- `Added` flag `--autotruncate` to `lino push` command. This flag will enable a truncate on each value based each `dbinfo`.`length` parameters set in the table.yaml file for each columns.
28-
- `Added` property `dbinfo`.`bytes` to column definition in table.yaml file. Set it to true to truncate the value based on a maximum number of bytes and not characters (assuming utf-8 encoding for now).
29-
- `Added` flags `--max-length` and `--bytes` to `lino table add-column` command. Use it to edit the properties `dbinfo`.`length` and `dbinfo`.`bytes` of the table.yaml file.
25+
- `Added` columns information and export type using the `lino table extract` command, columns and keys organized according to the database order
26+
- `Added` flag `--only-tables` to `lino table extract` command. This flag allows for the extraction of table information exclusively, excluding columns. It has been included to maintain the previous behavior
27+
- `Added` flag `--with-db-infos` to `lino table extract` command. This flag enables the extraction of information regarding column types, length, size, and precision if the column has been configured with these specifications
28+
- `Added` flag `--autotruncate` to `lino push` command. This flag will enable a truncate on each value based each `dbinfo`.`length` parameters set in the table.yaml file for each columns
29+
- `Added` property `dbinfo`.`bytes` to column definition in table.yaml file. Set it to true to truncate the value based on a maximum number of bytes and not characters (assuming utf-8 encoding for now)
30+
- `Added` flags `--max-length` and `--bytes` to `lino table add-column` command. Use it to edit the properties `dbinfo`.`length` and `dbinfo`.`bytes` of the table.yaml file
3031

3132
## [2.6.1]
3233

pkg/push/model_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (t table) Import(row map[string]interface{}) (ImportedRow, *Error) {
186186

187187
// autotruncate
188188
value, exists := result.GetValue(key)
189-
if exists && col.Truncate() && col.Length() > 0 && value.GetFormat() == jsonline.String {
189+
if exists && col.Truncate() && col.Length() > 0 && value.GetFormat() == jsonline.String && result.GetOrNil(key) != nil {
190190
if col.LengthInBytes() {
191191
result.Set(key, truncateUTF8String(result.GetString(key), int(col.Length())))
192192
} else {

tests/suites/push/autotruncate.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ testcases:
6262
- result.code ShouldEqual 0
6363
- result.systemout ShouldEqual {"actor_id":1,"first_name":"VÉRY VÉRY VÉRY VÉRY VÉRY VÉRY VÉRY 11","last_name":"GUINESS"}
6464
- result.systemerr ShouldBeEmpty
65+
66+
- name: truncate should not crash on null value
67+
steps:
68+
- script: echo '{"address_id":1,"address":"47 MySakila Drive","address2":null,"district":"Alberta","city_id":300,"postal_code":"","phone":""}' | lino push update dest --table address --autotruncate

0 commit comments

Comments
 (0)