Skip to content

Investigate usage of package_show in cycles  #219

@roll

Description

@roll

Overview

Code like this was sometimes failing with Exception: Action function package_show did not call its auth function:

def some_helper():
    context = {'model': model}

    # Get datasets
    datasets = []
    ids = normalize_list(value)
    for id in ids:
        try:
            dataset = tk.get_action('package_show')(context, {'id': id})
            href = tk.url_for('ckanext_showcase_read', id=dataset['name'], qualified=False)
            datasets.append({'text': dataset['title'], 'href': href})
        except tk.ObjectNotFound:
            pass

    return datasets

Moving context definition inside the cycle solved this problem:

def some_helper():

    # Get datasets
    datasets = []
    ids = normalize_list(value)
    for id in ids:
        try:
            dataset = tk.get_action('package_show')({'model': model}, {'id': id})
            href = tk.url_for('ckanext_showcase_read', id=dataset['name'], qualified=False)
            datasets.append({'text': dataset['title'], 'href': href})
        except tk.ObjectNotFound:
            pass

    return datasets

We have more functions like this but it seems it doesn't create any problems, for now. But anyway it makes sense to double check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions