Échec de la lecture des revues sans durée : "ValueError: invalid literal for int() with base 10: 'None'" #6

Closed
opened 2024-06-23 16:47:25 +02:00 by pilou · 3 comments

Au niveau des revues, les durées inexistantes sont sauvegardées avec None alors qu'une chaine vide est attendue:

Lu: 20100507-12h00 5, écrit 20100507-12h00 5 None

Jun 23 16:18:25 bots systemd[1]: Started hebdobot-v3.service - "Hebdobot v3 en python".
Jun 23 16:19:47 bots python3[1940107]: Traceback (most recent call last):
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/src/hebdobot.py", line 91, in 
Jun 23 16:19:47 bots python3[1940107]:     HebdoBot(settings).start()
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/bot.py", line 348, in start
Jun 23 16:19:47 bots python3[1940107]:     super().start()
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 1272, in start
Jun 23 16:19:47 bots python3[1940107]:     self.reactor.process_forever()
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 916, in process_forever
Jun 23 16:19:47 bots python3[1940107]:     consume(repeatfunc(one))
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/more_itertools/recipes.py", line 184, in consume
Jun 23 16:19:47 bots python3[1940107]:     deque(iterator, maxlen=0)
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 897, in process_once
Jun 23 16:19:47 bots python3[1940107]:     self.process_data(in_)
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 862, in process_data
Jun 23 16:19:47 bots python3[1940107]:     conn.process_data()
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 338, in process_data
Jun 23 16:19:47 bots python3[1940107]:     self._process_line(line)
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 369, in _process_line
Jun 23 16:19:47 bots python3[1940107]:     handler(arguments, command, source, tags)
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 413, in _handle_message
Jun 23 16:19:47 bots python3[1940107]:     self._handle_event(event)
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 446, in _handle_event
Jun 23 16:19:47 bots python3[1940107]:     self.reactor._handle_event(self, event)
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 992, in _handle_event
Jun 23 16:19:47 bots python3[1940107]:     result = handler.callback(connection, event)
Jun 23 16:19:47 bots python3[1940107]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 1229, in _dispatcher
Jun 23 16:19:47 bots python3[1940107]:     method(connection, event)
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/src/hebdobot.py", line 73, in on_pubmsg
Jun 23 16:19:47 bots python3[1940107]:     if hook.process(self, channel, sender, message):
Jun 23 16:19:47 bots python3[1940107]:        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/src/hooks/finish_review.py", line 46, in process
Jun 23 16:19:47 bots python3[1940107]:     stats.load()
Jun 23 16:19:47 bots systemd[1]: hebdobot-v3.service: Main process exited, code=exited, status=1/FAILURE
Jun 23 16:19:47 bots python3[1940107]:   File "/srv/hebdobot-py/src/review/stats.py", line 162, in load
Jun 23 16:19:47 bots python3[1940107]:     int(datas[2]),
Jun 23 16:19:47 bots python3[1940107]:     ^^^^^^^^^^^^^
Jun 23 16:19:47 bots python3[1940107]: ValueError: invalid literal for int() with base 10: 'None'
Jun 23 16:19:47 bots systemd[1]: hebdobot-v3.service: Failed with result 'exit-code'.
Au niveau des revues, les durées inexistantes sont [sauvegardées avec `None`](https://forge.april.org/mindiell/hebdobot/src/commit/59a1a79c82b0f16840297b6dbc8c0ef4e53d073c/review/review.py#L67) alors qu'une chaine vide [est attendue](https://forge.april.org/mindiell/hebdobot/src/commit/59a1a79c82b0f16840297b6dbc8c0ef4e53d073c/review/stats.py#L157-L164): Lu: <code>20100507-12h00 5</code>, écrit <code>20100507-12h00 5 None</code> <pre> Jun 23 16:18:25 bots systemd[1]: Started hebdobot-v3.service - "Hebdobot v3 en python". Jun 23 16:19:47 bots python3[1940107]: Traceback (most recent call last): Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/src/hebdobot.py", line 91, in <module> Jun 23 16:19:47 bots python3[1940107]: HebdoBot(settings).start() Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/bot.py", line 348, in start Jun 23 16:19:47 bots python3[1940107]: super().start() Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 1272, in start Jun 23 16:19:47 bots python3[1940107]: self.reactor.process_forever() Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 916, in process_forever Jun 23 16:19:47 bots python3[1940107]: consume(repeatfunc(one)) Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/more_itertools/recipes.py", line 184, in consume Jun 23 16:19:47 bots python3[1940107]: deque(iterator, maxlen=0) Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 897, in process_once Jun 23 16:19:47 bots python3[1940107]: self.process_data(in_) Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 862, in process_data Jun 23 16:19:47 bots python3[1940107]: conn.process_data() Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 338, in process_data Jun 23 16:19:47 bots python3[1940107]: self._process_line(line) Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 369, in _process_line Jun 23 16:19:47 bots python3[1940107]: handler(arguments, command, source, tags) Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 413, in _handle_message Jun 23 16:19:47 bots python3[1940107]: self._handle_event(event) Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 446, in _handle_event Jun 23 16:19:47 bots python3[1940107]: self.reactor._handle_event(self, event) Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 992, in _handle_event Jun 23 16:19:47 bots python3[1940107]: result = handler.callback(connection, event) Jun 23 16:19:47 bots python3[1940107]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/venv/lib/python3.11/site-packages/irc/client.py", line 1229, in _dispatcher Jun 23 16:19:47 bots python3[1940107]: method(connection, event) Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/src/hebdobot.py", line 73, in on_pubmsg Jun 23 16:19:47 bots python3[1940107]: if hook.process(self, channel, sender, message): Jun 23 16:19:47 bots python3[1940107]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/src/hooks/finish_review.py", line 46, in process Jun 23 16:19:47 bots python3[1940107]: stats.load() Jun 23 16:19:47 bots systemd[1]: hebdobot-v3.service: Main process exited, code=exited, status=1/FAILURE Jun 23 16:19:47 bots python3[1940107]: File "/srv/hebdobot-py/src/review/stats.py", line 162, in load Jun 23 16:19:47 bots python3[1940107]: int(datas[2]), Jun 23 16:19:47 bots python3[1940107]: ^^^^^^^^^^^^^ Jun 23 16:19:47 bots python3[1940107]: ValueError: invalid literal for int() with base 10: 'None' Jun 23 16:19:47 bots systemd[1]: hebdobot-v3.service: Failed with result 'exit-code'. </pre>
Author

Proposition de patch:

diff --git a/review/stats.py b/review/stats.py
index 89e341a..baa8c8d 100644
--- a/review/stats.py
+++ b/review/stats.py
@@ -1,4 +1,4 @@
-from dataclasses import dataclass
+from dataclasses import dataclass, field
 from datetime import datetime
 import re
 
@@ -7,7 +7,7 @@ import re
 class ReviewData:
     date: datetime
     user_count: int
-    duration: int
+    duration: int = field(default=10)
 
 
 class Board:
Proposition de patch: ```diff diff --git a/review/stats.py b/review/stats.py index 89e341a..baa8c8d 100644 --- a/review/stats.py +++ b/review/stats.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field from datetime import datetime import re @@ -7,7 +7,7 @@ import re class ReviewData: date: datetime user_count: int - duration: int + duration: int = field(default=10) class Board: ```
Owner

Je suis étonné par ça, normalement il devrait passer au-dessus et fournir 5 et None... Je vais rajouter des tests.

Je suis étonné par ça, normalement il devrait passer au-dessus et fournir 5 et None... Je vais rajouter des tests.
Owner

Ok, pigé, il y a bien une tabulation, puis une chaine vide. J'ai ajouté des tests en conséquence.

Ok, pigé, il y a bien une tabulation, puis une chaine vide. J'ai ajouté des tests en conséquence.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mindiell/hebdobot#6
No description provided.