Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache init parametes bug #18

Closed
juditnovak opened this issue Oct 29, 2019 · 5 comments · Fixed by #19
Closed

Cache init parametes bug #18

juditnovak opened this issue Oct 29, 2019 · 5 comments · Fixed by #19

Comments

@juditnovak
Copy link

https://github.com/ipinfo/python/blob/master/ipinfo/handler.py#L42

In case cache_options was defined, we end up "re-seinding" it, after having retrieved maxsize and ttl from the same dictionary. This way we multiply the same parameter in the function call, thus it can't perform.

@coderholic
Copy link
Member

What do you mean "it can't perform"? They're set separately because they have defaults.

@juditnovak
Copy link
Author

Sorry, my report wasn't sufficiently verbose.

Calling the getHandler() function with cache_options parameters, such as

handler = ipinfo.getHandler(
    IPINFO_TOKEN,
    cache_options={
        'ttl': IPINFO_CACHE_TTL,
        'maxsize': IPINFO_CACHE_SIZE
    }
)

results in:

Traceback (most recent call last):
  File "ipinfo_test.py", line 12, in <module>
    'maxsize': IPINFO_CACHE_SIZE
  File "/home/judit/.virtualenvs/logstore-EsX514WN/lib/python3.7/site-packages/ipinfo/__init__.py", line 6, in getHandler
    return Handler(access_token, **kwargs)
  File "/home/judit/.virtualenvs/logstore-EsX514WN/lib/python3.7/site-packages/ipinfo/handler.py", line 42, in __init__
    self.cache = DefaultCache(maxsize, ttl, **cache_options)
TypeError: __init__() got multiple values for argument 'ttl'

(This was what I meant, by 'can not perform' :-) )

The reason is https://github.com/ipinfo/python/blob/master/ipinfo/handler.py#L42 .

We are setting default values for maxsize and ttl (in case they were not defined). However, in case they were defined, we end up sending both named parameters a second time, in **cache_options

@UmanShahzad
Copy link
Contributor

Thanks for the report @juditnovak. We'll fix that up and make a release.

UmanShahzad added a commit that referenced this issue Oct 30, 2019
[#18] Properly choose defaults for cache maxsize and ttl
@UmanShahzad
Copy link
Contributor

UmanShahzad commented Oct 30, 2019

@juditnovak Changed up the interface to DefaultCache a bit in this fix, so in case anyone was using it directly I've bumped the version to 3.0.0: https://pypi.org/project/ipinfo/3.0.0/

@juditnovak
Copy link
Author

Thx much, this is what I call a prompt response and a quick fix! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants