#60 AttributeError: 'dict' object has no attribute 'applies_to'
Closed: Fixed 5 years ago Opened 5 years ago by ralph.

I saw this in the staging instance. :)

utils        2017-08-17 21:29:42 ERROR   Returning 500 to user.
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/srv/greenwave/greenwave/api_v1.py", line 97, in make_decision
    if policy.applies_to(decision_context, product_version)]
AttributeError: 'dict' object has no attribute 'applies_to'

It seems to me the policies are misconfigured. Is /etc/greenwave/policies/fedora.yaml on the server?
I think it is not because it is missing from here

https://infrastructure.fedoraproject.org/cgit/ansible.git/tree/roles/openshift-apps/greenwave/files/buildconfig.yml

As un-Pythonic as it is, maybe we should add some type checks here when loading the policies, since it seems like this would be an easy mistake to make? Maybe we just check the overall object is an isntance of Policy, and maybe each Rule as well?

FYI, testing this with:

import json
import requests

url = 'https://greenwave-stg-web-greenwave.app.os.stg.fedoraproject.org/api/v1.0/decision'
data = dict(
    # https://pagure.io/greenwave/blob/master/f/conf/policies/fedora.yaml
    decision_context='bodhi_update_push_stable',
    product_version='fedora-26',
    subject=[
        {'item': 'zypper-1.13.31-1.fc26', 'type': 'koji_build'},
    ],
)
response = requests.post(url, json=data)
print response
print response.json()

# Currently prints
# <Response [500]>
# {u'message': u"'dict' object has no attribute 'applies_to'"}

As un-Pythonic as it is, maybe we should add some type checks here when loading the policies

:+1: - that sounds like a good course of action to me.

PR #70 for adding type checks.

Metadata Update from @ralph:
- Issue status updated to: Closed (was: Open)

5 years ago

Metadata Update from @dcallagh:
- Issue assigned to mjia
- Issue close_status updated to: Fixed
- Issue set to the milestone: 0.2

5 years ago

Login to comment on this ticket.

Metadata