#4712 Boolean values not well interpreted in options/update rest endpoint
Closed: Fixed a year ago by wombelix. Opened 4 years ago by fbo.

Whatever you use True or False to set a config option the option wiill be set as False. The workaround is to convert True by 1 and False by 0 to see the option value took in account. Should it be explained to the API documentation ?
Here is a reproducer : https://softwarefactory-project.io/paste/show/1713/


I believe this has been solved in the last release (5.12).

Could you test this in staging?

Metadata Update from @wombelix:
- Issue assigned to wombelix

a year ago

Can be closed, I used the reproducer @fbo shared, commented out the conversion from True > 1 and False to 0. I also added lines to see the value before and after the API call.

I did two tests, first when notify_on_pull-request_flag was True and I could set it to False via API as expected.

wombelix@geeko:~/tmp/testprj> python3 4712.py <apikey> wombelix_testprj
True
False

Second test was notify_on_pull-request_flag is False and I changed it to True via API.

wombelix@geeko:~/tmp/testprj> python3 4712.py <apikey> wombelix_testprj
False
True

So as @pingou mentioned, the Issue is already solved.

Adjusted reproducer for documentation purposes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/env python3

import sys
import requests


class PagureAPIClient():

    def __init__(
            self, baseurl, api_token):
        self.session = requests.Session()
        self.base_url = '%s/api/0/' % baseurl
        self.api_token = api_token
        self.headers = {'Authorization': 'token %s' % self.api_token}

    def get(self, url):
        ret = self.session.get(url, headers=self.headers)
        return ret.json()

    def post(self, url, params=None):
        ret = self.session.post(url, data=params, headers=self.headers)
        return ret.json()

    def get_config(self, project):
        path = '%s/options' % project
        return self.get(self.base_url + path)

    def set_config(self, project, params):
        path = '%s/options/update' % project
        return self.post(self.base_url + path, params)


if __name__ == "__main__":
    apikey = sys.argv[1]
    project = sys.argv[2]
    client = PagureAPIClient('https://pagure.io', apikey)

    config = client.get_config(project)['settings']
    print(config['notify_on_pull-request_flag'])
    config['notify_on_pull-request_flag'] = True
    # convert to make it work
    #for k, v in config.items():
    #    config[k] = 1 if v else 0
    client.set_config(project, config)
    config = client.get_config(project)['settings']
    print(config['notify_on_pull-request_flag'])

Metadata Update from @wombelix:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

a year ago

Login to comment on this ticket.

Metadata