Skip to content

Commit 3b14a24

Browse files
authored
fix: import file with null value (#332)
1 parent 57cffdb commit 3b14a24

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Types of changes
2020
- `Added` commands `set-parent-select` and `set-child-select` to `lino id`
2121
- `Added` `import: no` option for columns in `tables.yaml` configuration
2222
- `Added` `export: presence` option for columns in `tables.yaml` configuration
23+
- `Fixed` issue with `import: file` when data is null, will not fail anymore
2324

2425
## [3.0.2]
2526

pkg/push/model_table.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,14 @@ func (t table) Import(row map[string]interface{}) (ImportedRow, *Error) {
176176

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

179-
if format == "file" {
179+
if value, exists := result.GetValue(key); format == "file" && exists && value.GetFormat() == jsonline.String && value.Raw() != nil {
180180
bytes, err := t.filecache.Load(result.GetString(key))
181181
if err != nil {
182182
return ImportedRow{}, &Error{Description: err.Error()}
183183
}
184184
result.SetValue(key, jsonline.NewValueAuto(bytes))
185-
}
186-
187-
// autotruncate
188-
value, exists := result.GetValue(key)
189-
if exists && col.Truncate() && col.Length() > 0 && value.GetFormat() == jsonline.String && result.GetOrNil(key) != nil {
185+
} else if exists && col.Truncate() && col.Length() > 0 && value.GetFormat() == jsonline.String && result.GetOrNil(key) != nil {
186+
// autotruncate
190187
if col.LengthInBytes() {
191188
result.Set(key, truncateUTF8String(result.GetString(key), int(col.Length())))
192189
} else {

tests/suites/push/import.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ testcases:
125125
- result.code ShouldEqual 0
126126
- result.systemout ShouldBeEmpty
127127
- result.systemerr ShouldBeEmpty
128+
- script: lino pull --table staff source | jq -c '.picture=null' | lino push update --table staff dest
129+
assertions:
130+
- result.code ShouldEqual 0
131+
- result.systemout ShouldBeEmpty
132+
- result.systemerr ShouldBeEmpty
128133

129134
- name: import no
130135
steps:

0 commit comments

Comments
 (0)