Skip to content

Commit 7429f90

Browse files
committed
fix: match datastore when listing field names
Splits the `validate` flag into two parts, but keeps the `validate` flag to avoid making this tiny fix a breaking change. Altering the columns on fetch instead of saving to the database so that we still have a record of the original column names if needed. Closes: #247
1 parent a109e11 commit 7429f90

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

ckanext/versioned_datastore/logic/basic/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def get_fields(resource_id: str, version: Optional[int] = None) -> List[dict]:
219219
else:
220220
# we have details, order the fields using the order of the columns in the
221221
# original source
222-
column_order = details.get_columns(validate=False)
222+
column_order = details.get_columns(skip_empty=False)
223223

224224
def key(f: dict) -> int:
225225
try:

ckanext/versioned_datastore/model/details.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
from ckan.model import DomainObject, meta
4+
from splitgill.diffing import prepare_field_name
45
from sqlalchemy import BigInteger, Column, Table, UnicodeText
56

67
# this table stores general details about each version of each resource. Currently it only stores
@@ -28,22 +29,28 @@ class DatastoreResourceDetails(DomainObject):
2829
version.
2930
"""
3031

31-
def get_columns(self, validate=True):
32+
def get_columns(self, validate=None, skip_empty=True, fix_names=True):
3233
"""
3334
Retrieve the columns contained in this resource's version.
3435
35-
:param validate: if True (the default) then fullstops are replaced with
36-
underscores before returning the list of columns and any falsey columns
37-
(empty strings, Nones) are removed
36+
:param validate: for backwards compatibility; sets both skip_empty and fix_names
37+
:param skip_empty: if True, remove falsey (empty strings, Nones) columns
38+
(default True)
39+
:param fix_names: if True, change column names to match datastore/splitgill
40+
(default True)
3841
:returns: a list of column names in the order they were in the original data
3942
source
4043
"""
44+
if validate is not None:
45+
skip_empty = validate
46+
fix_names = validate
47+
4148
columns = []
4249
for column in json.loads(self.columns):
43-
if validate:
44-
if not column:
45-
continue
46-
column = column.replace('.', '_')
50+
if skip_empty and not column:
51+
continue
52+
if fix_names:
53+
column = prepare_field_name(column)
4754
columns.append(column)
4855
return columns
4956

0 commit comments

Comments
 (0)