与pymongo的Deepcopy循环

时间:2016-03-20 16:25:21

标签: python mongodb pymongo

所以我正在执行这个功能:

def getLatestRecord(self):
    transactions = self.db.transactions
    if transactions.count():
        sortedTransactions = transactions.find({"account": self.accountName}).sort("date", pymongo.DESCENDING)
        if sortedTransactions.count():
            return sortedTransactions[0]['date']

从集合中的最新记录中获取日期字段。有些时候(还没有设法确定原因)它会产生这种追溯:

Traceback (most recent call last):
  "AccountABC.py", line 30, in getLatestRecord
  return sortedTransactions[0]['date']
File "/usr/local/lib/python3.4/dist-packages/pymongo/cursor.py", line 532, in __getitem__
clone = self.clone()
File "/usr/local/lib/python3.4/dist-packages/pymongo/cursor.py", line 240, in clone
  return self._clone(True)
File "/usr/local/lib/python3.4/dist-packages/pymongo/cursor.py", line 253, in _clone
  data = self._deepcopy(data)
File "/usr/local/lib/python3.4/dist-packages/pymongo/cursor.py", line 1097, in _deepcopy
  value = self._deepcopy(value, memo)
File "/usr/local/lib/python3.4/dist-packages/pymongo/cursor.py", line 1099, in _deepcopy
  value = copy.deepcopy(value, memo)
File "/usr/lib/python3.4/copy.py", line 182, in deepcopy
  y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.4/copy.py", line 300, in _reconstruct
  state = deepcopy(state, memo)
File "/usr/lib/python3.4/copy.py", line 155, in deepcopy
  y = copier(x, memo)
File "/usr/lib/python3.4/copy.py", line 246, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.4/copy.py", line 182, in deepcopy
  y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.4/copy.py", line 300, in _reconstruct
  state = deepcopy(state, memo)
File "/usr/lib/python3.4/copy.py", line 155, in deepcopy
  y = copier(x, memo)
File "/usr/lib/python3.4/copy.py", line 246, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)

(... repeat a lot ...)
RuntimeError: maximum recursion depth exceeded while getting the str of an object

我在这里做坏事吗?

文件示例:

{ "_id" : ObjectId("000000000000000000"), "balance" : "£2", "description" : "A payment", "moneyIn" : "", "transactionId" : "0015589241040B832015-11-03", "date" : ISODate("2015-11-03T00:00:00Z"), "moneyOut" : "£1", "account" : "MAIN ACCOUNT" }

版本:

>>> pymongo.version
'3.1'

> db.version()
3.2.4

0 个答案:

没有答案