aioes icon indicating copy to clipboard operation
aioes copied to clipboard

Boolean parameter refresh is broken

Open neumond opened this issue 9 years ago • 10 comments

You can clearly see here conversion of parameter to boolean type. https://github.com/aio-libs/aioes/blob/master/aioes/client/init.py#L133 Then it fails here https://github.com/aio-libs/yarl/blob/master/yarl/init.py#L673

Considering this, there's no way to use refresh parameter at all.

neumond avatar Nov 22 '16 14:11 neumond

Monkeypatch workaround

    import yarl
    original_with_query = yarl.URL.with_query

    def new_with_query(self, *args, **kwargs):
        if kwargs:
            query = kwargs
        elif len(args) == 1:
            query = args[0]
        if isinstance(query, Mapping) and 'refresh' in query and isinstance(query['refresh'], bool):
            query['refresh'] = '1' if query['refresh'] else '0'
        return original_with_query(self, *args, **kwargs)

    yarl.URL.with_query = new_with_query

neumond avatar Nov 22 '16 21:11 neumond

Would you provide a patch which fixes aioes, without yarl monkeypatching?

asvetlov avatar Dec 07 '16 16:12 asvetlov

There're two ways of solving this problem: modifying yarl for bool support and replacing bool parameters everywhere is aioes. What can you consider correct?

neumond avatar Dec 08 '16 01:12 neumond

The second one

asvetlov avatar Dec 08 '16 15:12 asvetlov

Any plans on merging this and doing a new release soon?

wintamute avatar Feb 15 '17 16:02 wintamute

@wintamute I would prefer to be able to convert from bool instead passing as is. refresh=True looks more reasonable than refresh=1.

neumond avatar Feb 16 '17 06:02 neumond

@neumond I agree, I was referring to the commit above (https://github.com/DLizogub/aioes/commit/77c4d56b28f8c97f607d6d5b6c741120a4b091e6) Edit: I just checked that commit again, my bad, the fix should be to convert here to str instead of passing as is so that yarl doesn't complain later on. I didn't try it I admit. Using a local modified version doesn't really help me since I need a version the build system can just download.

wintamute avatar Feb 16 '17 09:02 wintamute

A less hackish monkey-patch to workaround this issue as well as #112


from aioes.connection import Connection

__original_perform_request = Connection.perform_request

def perform_request(self, method, url, params, body):
    url = url.lstrip('/')  # Fixes issue #112
    if params:
        for key, value in params.items():
            if isinstance(value, bool):
                params[key] = str(value).lower()
    return __original_perform_request(self, method, url, params, body)

Connection.perform_request = perform_request

kr41 avatar Mar 01 '17 16:03 kr41

Hey, guys! Please check this out with latest master!

popravich avatar Mar 23 '17 14:03 popravich

Looks very much so. Many thanks for giving some love to ES5 support.

haizaar avatar Apr 02 '17 08:04 haizaar