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
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: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 withDEL feed:user:13
, In case if that doesn't fix the issue then you canFLUSHALL
which will delete everything from Redis.Sample code:
The documentation is inconsistent. The
verb
you pass to the activity should be (an instance of?*) a subclass ofstream_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:
I quickly looked over the code for
Activity
and it looks like passingint
s foractor
andobject
should work. However, it is possible that these parameters are also outdated in the documentation.* The tests pass in classes as
verb
. However, theVerb
base class has the methodsserialize
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.