Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch error in datastore #8149

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes/8149.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Catch an error in datastore to avoid 500 error in POSTs to `datatables/ajax/<resource_view_id>`
The `datastore_search` action raises this error, it's captured later in this function but not here.
19 changes: 11 additions & 8 deletions ckanext/datatablesview/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ckan.common import json
from ckan.lib.helpers import decode_view_request_filters
from ckan.plugins.toolkit import get_action, request, h
from ckan.plugins.toolkit import get_action, request, h, ObjectNotFound
import re

datatablesview = Blueprint(u'datatablesview', __name__)
Expand Down Expand Up @@ -59,13 +59,16 @@ def ajax(resource_view_id: str):
filters = merge_filters(view_filters, user_filters)

datastore_search = get_action(u'datastore_search')
unfiltered_response = datastore_search(
{}, {
u"resource_id": resource_view[u'resource_id'],
u"limit": 0,
u"filters": view_filters,
}
)
try:
unfiltered_response = datastore_search(
{}, {
u"resource_id": resource_view[u'resource_id'],
u"limit": 0,
u"filters": view_filters,
}
)
except ObjectNotFound:
return json.dumps({'error': 'Object not found'})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the response datatables expects on errors? Does it render the text in a dialog box or something?

Should probably also set the response status to 404.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also catch NotAuthorized here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wardi This function is a response for a POST and only returns JSON with no status (even for errors).
https://github.com/ckan/ckan/blob/master/ckanext/datatablesview/blueprint.py#L141
I just add statu codes for all responses

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also catch NotAuthorized here

Added here avdata99@ff1b9d7


cols = [f[u'id'] for f in unfiltered_response[u'fields']]
if u'show_fields' in resource_view:
Expand Down