skip to Main Content

I’m trying to setup stream-framework the one here not the newer getstream. I’ve setup the Redis server and the environment properly, the issue I’m facing is in creating the activities for a user.

I’ve been trying to create activities, following the documentation to add an activity but it gives me an error message as follows:

...
  File "/Users/.../stream_framework/activity.py", line 110, in serialization_id
    if self.object_id >= 10 ** 10 or self.verb.id >= 10 ** 3:
AttributeError: 'int' object has no attribute 'id'

Here is the code

from stream_framework.activity import Activity
from stream_framework.feeds.redis import RedisFeed


class PinFeed(RedisFeed):
    key_format = 'feed:normal:%(user_id)s'

class UserPinFeed(PinFeed):
    key_format = 'feed:user:%(user_id)s'

feed = UserPinFeed(13)
print(feed)

activity = Activity(
    actor=13, # Thierry's user id
    verb=1, # The id associated with the Pin verb
    object=1, # The id of the newly created Pin object
)

feed.add(activity) # Error at this line

I think there is something missing in the documentation or maybe I’m doing something wrong. I’ll be very grateful if anyone helps me get the stream framework working properly.

2

Answers


  1. Chosen as BEST ANSWER

    With the help of great answer by @He3lixxx, I was able to solve it partially. As the package is no more maintained, the package installs the latest Redis client for python which was creating too many issues so by installation redis-2.10.5 if using stream-framework-1.3.7, should fix the issue.

    I would also like to add a complete guide to properly add activity to a user feed.

    Key points:

    • If you are not using feed manager, then make sure to first insert the activity before you add it to the user with feed.insert_activity(activity) method.

    • In case of getting feeds with feed[:] throws an error something like below:

      File "/Users/.../stream_framework/activity.py", line 44, in get_hydrated
            activity = activities[int(self.serialization_id)]
        KeyError: 16223026351730000000001005L
      

      then you need to clear data for that user using the key format for it in my case the key is feed:user:13 for user 13, delete it with DEL feed:user:13, In case if that doesn't fix the issue then you can FLUSHALL which will delete everything from Redis.

    Sample code:

    from stream_framework.activity import Activity
    from stream_framework.feeds.redis import RedisFeed
    from stream_framework.verbs import register
    from stream_framework.verbs.base import Verb
    
    class PinFeed(RedisFeed):
        key_format = 'feed:normal:%(user_id)s'
    
    class UserPinFeed(PinFeed):
        key_format = 'feed:user:%(user_id)s'
    
    class Pin(Verb):
        id = 5
        infinitive = 'pin'
        past_tense = 'pinned'
    register(Pin)
    
    
    feed = UserPinFeed(13)
    print(feed[:])
    
    activity = Activity(
        actor=13,
        verb=Pin,
        object=1)
    
    feed.insert_activity(activity)
    activity_id = feed.add(activity)
    
    print(activity_id)
    print(feed[:])
    

  2. The documentation is inconsistent. The verb you pass to the activity should be (an instance of?*) a subclass of stream_framework.verbs.base.Verb. Check out this documentation page on custom verbs and the tests for this class.

    The following should fix the error you posted:

    from stream_framework.activity import Activity
    from stream_framework.feeds.redis import RedisFeed
    from stream_framework.verbs import register
    from stream_framework.verbs.base import Verb
    
    class PinFeed(RedisFeed):
        key_format = 'feed:normal:%(user_id)s'
    
    class UserPinFeed(PinFeed):
        key_format = 'feed:user:%(user_id)s'
    
    class Pin(Verb):
        id = 5
        infinitive = 'pin'
        past_tense = 'pinned'
    
    register(Pin)
    
    feed = UserPinFeed(13)
    
    activity = Activity(
        actor=13,
        verb=Pin,
        object=1,
    )
    
    feed.add(activity)
    

    I quickly looked over the code for Activity and it looks like passing ints for actor and object should work. However, it is possible that these parameters are also outdated in the documentation.


    * The tests pass in classes as verb. However, the Verb base class has the methods serialize and __str__ that can only be meaningfully invoked if you have an object of this class. So I’m still unsure which is required here. It seems like in the current state, the framework never calls these methods, so classes still work, but I feel like the author originally intended to pass instances.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search