Subscription class suggestion
0

2 posts in this topic

Hi, I was going to do this as a pull request but it appears you need permission for that.

There's a (easily fixable) limitation with `ftrack_api.event.subscription.Subscription` in that if the object given to it is a non-string object, it will fail because it's returning the object itself inside `Subscription.__str__`. My suggestion is to call the objects `__str__` method when the class is initialised.

n my particular use case, I have an object containing multiple parts of a query, and it will generate the final query after being converted to a string. It seems a bit redundant doing `event_hub.subscribe(str(obj))` when `obj` acts like a string in every way other than type.

Current

def __init__(self, subscription):
    '''Initialise with *subscription*.'''
    self._subscription = subscription
    self._expression = self.parser.parse(_subscription)
        
# Traceback (most recent call last):
#   File "file.py", line 89, in <module>
#     session.event_hub.subscribe(<some object>, callback)
#   File "ftrack_api\event\hub.py", line 436, in subscribe
#     self._notify_server_about_subscriber(subscriber)
#   File "ftrack_api\event\hub.py", line 491, in _notify_server_about_subscriber
#     subscription=str(subscriber.subscription)
# TypeError: __str__ returned non-string (type <some object>)

Proposed

def __init__(self, subscription):
    '''Initialise with *subscription*.'''
    self._subscription = str(subscription)
    self._expression = self.parser.parse(self._subscription)

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
0