Skip to content

Commit

Permalink
fix: import file with null value (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury authored Nov 21, 2024
1 parent 57cffdb commit 3b14a24
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Types of changes
- `Added` commands `set-parent-select` and `set-child-select` to `lino id`
- `Added` `import: no` option for columns in `tables.yaml` configuration
- `Added` `export: presence` option for columns in `tables.yaml` configuration
- `Fixed` issue with `import: file` when data is null, will not fail anymore

## [3.0.2]

Expand Down
9 changes: 3 additions & 6 deletions pkg/push/model_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,14 @@ func (t table) Import(row map[string]interface{}) (ImportedRow, *Error) {

format, _ := parseFormatWithType(col.Import())

if format == "file" {
if value, exists := result.GetValue(key); format == "file" && exists && value.GetFormat() == jsonline.String && value.Raw() != nil {
bytes, err := t.filecache.Load(result.GetString(key))
if err != nil {
return ImportedRow{}, &Error{Description: err.Error()}
}
result.SetValue(key, jsonline.NewValueAuto(bytes))
}

// autotruncate
value, exists := result.GetValue(key)
if exists && col.Truncate() && col.Length() > 0 && value.GetFormat() == jsonline.String && result.GetOrNil(key) != nil {
} else if exists && col.Truncate() && col.Length() > 0 && value.GetFormat() == jsonline.String && result.GetOrNil(key) != nil {
// autotruncate
if col.LengthInBytes() {
result.Set(key, truncateUTF8String(result.GetString(key), int(col.Length())))
} else {
Expand Down
5 changes: 5 additions & 0 deletions tests/suites/push/import.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ testcases:
- result.code ShouldEqual 0
- result.systemout ShouldBeEmpty
- result.systemerr ShouldBeEmpty
- script: lino pull --table staff source | jq -c '.picture=null' | lino push update --table staff dest
assertions:
- result.code ShouldEqual 0
- result.systemout ShouldBeEmpty
- result.systemerr ShouldBeEmpty

- name: import no
steps:
Expand Down

0 comments on commit 3b14a24

Please sign in to comment.