Skip to content

Commit b00bcfe

Browse files
authored
Merge pull request #138 from open-data/fix/load-csv
Fix Load CSV Command
2 parents 5c30d7a + 1a08794 commit b00bcfe

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

changes/138.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed an issue with the `load_csv` command in which it would raise exceptions when passing non-existing fields to the DataStore.

ckanext/recombinant/cli.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,19 @@ def _load_one_csv_file(name: str) -> int:
519519

520520
click.echo('- %s %s' % (org_name, len(records)))
521521

522+
# default org extras
523+
org_extras = [
524+
'owner_org',
525+
'owner_org_title'
526+
]
522527
if 'csv_org_extras' in chromo:
523-
# remove 'csv_org_extras' fields from records
524-
for r in records:
525-
for e in chromo['csv_org_extras']:
526-
del r[e]
528+
org_extras += chromo['csv_org_extras']
529+
# remove any org extras
530+
for r in records:
531+
for e in org_extras:
532+
if e not in r:
533+
continue
534+
del r[e]
527535

528536
offset = 0
529537
while offset < len(records):
@@ -624,6 +632,7 @@ def _write_one_csv(lc: LocalCKAN,
624632
chromo['resource_name'], pkg['owner_org']))
625633
continue
626634

635+
# default org extras
627636
org_extras = {
628637
'owner_org': pkg['owner_org'],
629638
'owner_org_title': pkg['org_title'],

ckanext/recombinant/read_csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def csv_data_batch(csv_path: str,
4848
if f['datastore_type'] != 'text']
4949

5050
for row_dict in csv_in:
51-
owner_org = row_dict.pop('owner_org')
51+
owner_org = row_dict.pop('owner_org', None)
5252
if owner_org != current_owner_org:
5353
if records:
5454
yield (current_owner_org, records)

0 commit comments

Comments
 (0)