create account

Beem: account.history_reverse() may fail with TypeError by stmdev

View this thread on: hive.blogpeakd.comecency.com
· @stmdev · (edited)
$59.67
Beem: account.history_reverse() may fail with TypeError
#### Project Information
* Repository: https://github.com/holgern/beem
* Project Name: Beem
* Publisher: @holger80

#### Expected behavior
`account.history_reverse(start=start, stop=stop, only_ops=['comment'])` with `start` and `stop` being `datetime` objects should return the all `comment` operations of an account in the given time range.

#### Actual behavior
`account.history_reverse(start=start, stop=stop, only_ops=['comment'])` may fail with a `TypeError` exception:

```
Traceback (most recent call last):
  File "account_history_reverse.py", line 10, in <module>
    for op in a.history_reverse(start=start, stop=stop, only_ops=['comment']):
  File "/usr/local/lib/python3.6/site-packages/beem/account.py", line 1335, in history_reverse
    while(op_est + est_diff + batch_size < first and block_date < start):
TypeError: '<' not supported between instances of 'str' and 'datetime.datetime'
```

`block_date` is a string in this case and is compared to `start` as a `datetime` object.


#### How to reproduce
```python
#!/usr/bin/python
from beem.account import Account
from datetime import datetime, timedelta
from beem.utils import addTzInfo

a = Account("steemcleaners")
start = addTzInfo(datetime.utcnow()) - timedelta(days=1)
stop = addTzInfo(datetime.utcnow()) - timedelta(days=7)
for op in a.history_reverse(start=start, stop=stop, only_ops=['comment']):
    print(op)
```
![screenshot.png](https://cdn.steemitimages.com/DQmVQDt9GVenf71Kdw3khHgdqtmvSFzMJDz43cPaFeP1Z9C/screenshot.png)

#### Possible fix
Suspicion: `block_date` is converted to datetime objects in other places with `formatTimeString()`. This is not the case for the failing location, `h["timestamp"]` is used directly as a string.

Possible Fix:
```patch
diff --git a/beem/account.py b/beem/account.py
index b41cb58..b4ca42f 100644
--- a/beem/account.py
+++ b/beem/account.py
@@ -1331,13 +1331,13 @@ class Account(BlockchainObject):
             est_diff = 0
             if isinstance(start, (datetime, date, time)):
                 for h in self.get_account_history(op_est, 0):
-                    block_date = h["timestamp"]
+                    block_date = formatTimeString(h["timestamp"])
                 while(op_est + est_diff + batch_size < first and block_date < start):
                     est_diff += batch_size
                     if op_est + est_diff > first:
                         est_diff = first - op_est
                     for h in self.get_account_history(op_est + est_diff, 0):
-                        block_date = h["timestamp"]
+                        block_date = formatTimeString(h["timestamp"])
             else:
                 for h in self.get_account_history(op_est, 0):
                     block_num = h["block"]
```

#### Environment
```
# beempy --version
beempy, version 0.19.32
# python --version
Python 3.6.5
```

#### GitHub Account
https://github.com/crokkon
A Github issue has been created: https://github.com/holgern/beem/issues/13
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorstmdev
permlinkbeem-account-historyreverse-may-fail-with-typeerror
categoryutopian-io
json_metadata{"tags":["utopian-io","bug-hunting","beem","python","steemdev"],"users":["holger80"],"links":["https://github.com/holgern/beem","https://github.com/crokkon","https://github.com/holgern/beem/issues/13"],"app":"steemit/0.1","format":"markdown","image":["https://cdn.steemitimages.com/DQmVQDt9GVenf71Kdw3khHgdqtmvSFzMJDz43cPaFeP1Z9C/screenshot.png"]}
created2018-05-28 07:18:15
last_update2018-05-28 08:37:30
depth0
children4
last_payout2018-06-04 07:18:15
cashout_time1969-12-31 23:59:59
total_payout_value45.172 HBD
curator_payout_value14.502 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,969
author_reputation10,427,398,400,460
root_title"Beem: account.history_reverse() may fail with TypeError"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id58,067,048
net_rshares14,655,088,439,777
author_curate_reward""
vote details (41)
@holger80 · (edited)
$0.05
Thanks for the PR and the issue report.
I already merged the [PR](https://github.com/holgern/beem/pull/14) [here](https://github.com/holgern/beem/commit/bd8cf746f7a3287654c9084da6e641bb4838e7ca)
πŸ‘  
properties (23)
authorholger80
permlinkre-stmdev-beem-account-historyreverse-may-fail-with-typeerror-20180528t091021375z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://github.com/holgern/beem/pull/14","https://github.com/holgern/beem/commit/bd8cf746f7a3287654c9084da6e641bb4838e7ca"],"app":"steemit/0.1"}
created2018-05-28 09:10:21
last_update2018-05-28 09:10:36
depth1
children1
last_payout2018-06-04 09:10:21
cashout_time1969-12-31 23:59:59
total_payout_value0.036 HBD
curator_payout_value0.009 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length194
author_reputation358,857,509,568,825
root_title"Beem: account.history_reverse() may fail with TypeError"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id58,079,494
net_rshares12,065,159,614
author_curate_reward""
vote details (1)
@crokkon · (edited)
.
.
properties (22)
authorcrokkon
permlinkre-holger80-re-stmdev-beem-account-historyreverse-may-fail-with-typeerror-20180528t115217408z
categoryutopian-io
json_metadata"{"app": ""}"
created2018-05-28 11:52:18
last_update2022-09-18 11:51:12
depth2
children0
last_payout2018-06-04 11:52:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1
author_reputation81,214,366,861,104
root_title"Beem: account.history_reverse() may fail with TypeError"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id58,097,773
net_rshares0
@knowledges ·
$0.09
Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/5/2131113).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  ,
properties (23)
authorknowledges
permlinkre-stmdev-beem-account-historyreverse-may-fail-with-typeerror-20180528t205324483z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/5/2131113","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-05-28 20:53:27
last_update2018-05-28 20:53:27
depth1
children0
last_payout2018-06-04 20:53:27
cashout_time1969-12-31 23:59:59
total_payout_value0.086 HBD
curator_payout_value0.004 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length489
author_reputation98,021,227,622,369
root_title"Beem: account.history_reverse() may fail with TypeError"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id58,171,019
net_rshares22,821,237,469
author_curate_reward""
vote details (2)
@utopian-io ·
$0.04
Hey @stmdev
**Thanks for contributing on Utopian**.
Congratulations! Your contribution was Staff Picked to receive a maximum vote for the bug-hunting category on Utopian for being of significant value to the project and the open source community.

We’re already looking forward to your next contribution!

**Contributing on Utopian**
Learn how to contribute on <a href='https://join.utopian.io'>our website</a> or by watching <a href='https://www.youtube.com/watch?v=8S1AtrzYY1Q'>this tutorial</a> on Youtube.

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
πŸ‘  
properties (23)
authorutopian-io
permlinkre-beem-account-historyreverse-may-fail-with-typeerror-20180529t072208z
categoryutopian-io
json_metadata"{"app": "beem/0.19.29"}"
created2018-05-29 07:22:09
last_update2018-05-29 07:22:09
depth1
children0
last_payout2018-06-05 07:22:09
cashout_time1969-12-31 23:59:59
total_payout_value0.029 HBD
curator_payout_value0.007 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length699
author_reputation152,955,367,999,756
root_title"Beem: account.history_reverse() may fail with TypeError"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id58,234,770
net_rshares9,546,073,778
author_curate_reward""
vote details (1)