Closed ghost closed 5 years ago
You're overwriting body with empty string, which is not the same as None. So may be a better way is to create a local variable body = None if body is not None else body[:20]
and use it in final result
@sibiryakov I think this is a bug, what do you think?
Why do I overwrite the body with an empty string is that it should be an empty string.
You're overwriting body with empty string, which is not the same as None. So may be a better way is to create a local variable
body = None if body is not None else body[:20]
and use it in final result
It cannot be self._body = None if self.body is not None else self.body[:20]
, because if not None mean the body contain strings, but you override the strings with None, and cause the None pass to body[:20].
Traceback (most recent call last):
File "temp.py", line 44, in <module>
print(message)
File "/opt/anaconda3/lib/python3.7/site-packages/frontera/core/models.py", line 168, in __str__
self._body = None if self.body is not None else self.body[:20]
TypeError: 'NoneType' object is not subscriptable
I think should be str(self.body[:20]) if self.body is not None else None
and i have made a PR.
https://github.com/scrapinghub/frontera/pull/375/commits/13efd27cf8bbd7e2d1fdf24b05ba4524df11fe57
Fixed by #375
I have modified the frontera/core/models.py
Because sometime the self.body return none, but I am not sure this is the best way to solve the problem.