<commit_before>import json

from pylons import config

import ckan.model as model
import ckan.lib.helpers as helpers
from ckan.controllers.package import PackageController

import ckan.plugins as p

from ckanext.glasgow.logic.action import (
    ECAPINotAuthorized,
    ECAPIError,
)


class DatasetController(PackageController):

    def read(self, id, format='html'):

        pending_task = p.toolkit.get_action('pending_task_for_dataset')({
            'ignore_auth': True}, {'id': id})

        if (pending_task and
                pending_task['task_type'] == 'dataset_request_create'):
            pending_task['value'] = json.loads(pending_task['value'])

            context = {
                'model': model,
                'session': model.Session,
            }

            try:
                change_requests = p.toolkit.get_action('get_change_request')(
                    context, {'id': pending_task['value'].get('request_id')})
                if change_requests:
                    change_request = change_requests[-1]
            except ECAPIError, e:
                change_request = None
                #flash
            except p.toolkit.NotAuthorized:
                change_request = None

            vars = {
                'task': pending_task,
                'change_request': change_request,
            }
            return p.toolkit.render('package/read_pending.html',
                                    extra_vars=vars)
        else:
            return super(DatasetController, self).read(id, format)
<commit_msg>fix dataset controller for empty change requests<commit_after>import json

from pylons import config

import ckan.model as model
import ckan.lib.helpers as helpers
from ckan.controllers.package import PackageController

import ckan.plugins as p

from ckanext.glasgow.logic.action import (
    ECAPINotAuthorized,
    ECAPIError,
)


class DatasetController(PackageController):

    def read(self, id, format='html'):

        pending_task = p.toolkit.get_action('pending_task_for_dataset')({
            'ignore_auth': True}, {'id': id})

        if (pending_task and
                pending_task['task_type'] == 'dataset_request_create'):
            pending_task['value'] = json.loads(pending_task['value'])

            context = {
                'model': model,
                'session': model.Session,
            }

            try:
                change_requests = p.toolkit.get_action('get_change_request')(
                    context, {'id': pending_task['value'].get('request_id')})
                if change_requests:
                    change_request = change_requests[-1]
                else:
                    change_request = None
            except ECAPIError, e:
                change_request = None
                #flash
            except p.toolkit.NotAuthorized:
                change_request = None

            vars = {
                'task': pending_task,
                'change_request': change_request,
            }
            return p.toolkit.render('package/read_pending.html',
                                    extra_vars=vars)
        else:
            return super(DatasetController, self).read(id, format)

{'fraction_non_alphanumeric': 0.09348706762231225, 'fraction_numerical': 0.0006232471174820816, 'mean_word_length': 1.8533333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '234842', 'n_tokens_mistral': 864, 'n_tokens_neox': 827, 'n_words': 177}