danielfm / pybreaker

Python implementation of the Circuit Breaker pattern.
BSD 3-Clause "New" or "Revised" License
508 stars 74 forks source link

Python 3 support #51

Closed AvnerCohen closed 4 years ago

AvnerCohen commented 4 years ago

In: https://github.com/danielfm/pybreaker/blob/945b3ff79dab76a4e820144e77cfe0bde6e0ad4f/src/pybreaker.py#L512

state = state_bytes.decode('utf-8')

This fails in python 3 with:

AttributeError: 'str' object has no attribute 'decode'

Any plans to fix this, will a PR help on this one?

danielfm commented 4 years ago

Hey! Which is the Python 3 version exactly?

AvnerCohen commented 4 years ago

3.7.4, but quite sure this is a 3.7.x thing.

danielfm commented 4 years ago

I ran the test cases in my machine with Python 3.7.5 and all tests passed.

If you manage to reproduce the issue in a test case and provide a pull request fixing the issue, I'll be happy to merge it.

AvnerCohen commented 4 years ago

@danielfm

  1. Thanks so much for the quick response and checking this out.
  2. Apologies as this was my bad, I wrongly went into the python 3.x direction.

Seems like this happened when I initiated the redis client with auto response decoding:

redis = StrictRedis.from_url(url, {'decode_responses': True})

Dropping this solved the Exception I got:

    state_storage=pybreaker.CircuitRedisStorage(pybreaker.STATE_CLOSED, redis))
  File "/venv/site-packages/pybreaker.py", line 61, in __init__
    self._state = self._create_new_state(self.current_state)
  File "/venv/site-packages/pybreaker.py", line 155, in current_state
    return self._state_storage.state
  File "/venv/site-packages/pybreaker.py", line 512, in state
    state = state_bytes.decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'

Thanks.

danielfm commented 4 years ago

Glad to know. We should probably update the README to document this gotcha so other users don't waste their precious time. :)