Skip to content

Commit

Permalink
[#3816] datastore_search with missing _id column
Browse files Browse the repository at this point in the history
  • Loading branch information
wardi committed Sep 15, 2017
1 parent 164b986 commit 1e1d032
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ckanext/datastore/backend/postgres.py
Expand Up @@ -151,8 +151,7 @@ def _rename_field(data_dict, term, replace):


def _get_fields_types(context, data_dict):
all_fields = _get_fields(context, data_dict)
all_fields.insert(0, {'id': '_id', 'type': 'int'})
all_fields = _get_fields(context, data_dict, include_id=True)
field_types = OrderedDict([(f['id'], f['type']) for f in all_fields])
return field_types

Expand Down Expand Up @@ -234,13 +233,13 @@ def _get_field_info(connection, resource_id):
return {}


def _get_fields(context, data_dict):
def _get_fields(context, data_dict, include_id=False):
fields = []
all_fields = context['connection'].execute(
u'SELECT * FROM "{0}" LIMIT 1'.format(data_dict['resource_id'])
)
for field in all_fields.cursor.description:
if not field[0].startswith('_'):
if (include_id and field[0].decode('utf-8') == '_id') or not field[0].startswith('_'):
fields.append({
'id': field[0].decode('utf-8'),
'type': _get_type(context, field[1])
Expand Down

0 comments on commit 1e1d032

Please sign in to comment.