2017-04-23 77 views
1

我試圖建立一個基本的飼料:錯誤與流框架

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) 

但是,當我加入一個活動後運行feed[:2],我不斷收到此錯誤:

<ipython-input-25-41b7cd0d0d8c> in <module>() 
----> 1 feed[:2] 

/Users/home/venv/lib/python2.7/site-packages/stream_framework/feeds/base.pyc in __getitem__(self, k) 
    303   try: 
    304    results = self.get_activity_slice(
--> 305     start, bound) 
    306   except StopIteration: 
    307    # There's nothing left, even though the bound is higher. 

/Users/home/venv/lib/python2.7/site-packages/stream_framework/feeds/base.pyc in get_activity_slice(self, start, stop, rehydrate) 
    354   print 'line 350' 
    355   if self.needs_hydration(activities) and rehydrate: 
--> 356    activities = self.hydrate_activities(activities) 
    357   return activities 
    358 

/Users/home/venv/lib/python2.7/site-packages/stream_framework/feeds/base.pyc in hydrate_activities(self, activities) 
    332   activity_data = {a.serialization_id: a for a in activity_list} 
    333   print activity_data 
--> 334   return [activity.get_hydrated(activity_data) for activity in activities] 
    335 
    336  def needs_hydration(self, activities): 

/Users/home/venv/lib/python2.7/site-packages/stream_framework/activity.pyc in get_hydrated(self, activities) 
    42 
    43   ''' 
---> 44   activity = activities[int(self.serialization_id)] 
    45   activity.dehydrated = False 
    46   return activity 

KeyError: 14929294667170000000001005L 

我能夠打印出[<stream_framework.activity.DehydratedActivity object at 0x10e114e90>][u'14929294667170000000001005']

任何線索可能導致這種情況?

回答

2

有一個在KeyError堆棧跟蹤示出的類型不匹配這裏,關鍵是和之間的[u'14929294667170000000001005']

u'14929294667170000000001005'打印輸出形式是Unicode字符串 而14929294667170000000001005Llong類型整數。

密鑰本身或您試圖用作查找密鑰的值將不得不更改,以便類型相同。請注意,帶有或不帶有L後綴(表示long類型)的int將用於從python dict中檢索值。一個簡單的演示:

>>> D = {14929294667170000000001005 : 'some value'} 
>>> D[14929294667170000000001005] 
'some value' 
>>> D[14929294667170000000001005L] 
'some value' 
+0

我知道這一點,但我使用框架,這樣的問題是,爲什麼它不是在框架 – Rob

+1

阿的界限工作,我明白了。 2014年1月13日「tbarbugli」的最後迴應在這個線程中:https://github.com/tschellenbach/Stream-Framework/issues/15 ...提到需要'insert_activity()'來防止相同的錯誤。 – JacobIRR

+0

似乎是問題,文檔似乎沒有這個要求 – Rob