Bug #103296
ValueError: year -1 is out of range
Status:
Nouveau
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
13 March 2025
Due date:
% Done:
0%
Estimated time:
Patch proposed:
No
Planning:
No
Description
https://sentry.entrouvert.org/entrouvert/publik/issues/138778/
ValueError: year -1 is out of range (14 additional frame(s) were not displayed) ... File "django/db/models/query.py", line 91, in __iter__ results = compiler.execute_sql( File "django/db/models/sql/compiler.py", line 1595, in execute_sql return list(result) File "django/db/models/sql/compiler.py", line 2093, in cursor_iter for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel): File "django/db/models/sql/compiler.py", line 2093, in <lambda> for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel): File "django/db/utils.py", line 98, in inner return func(*args, **kwargs)
History
Updated by Lauréline Guérin 3 days ago
diff --git a/tests/test_import_export.py b/tests/test_import_export.py index e5526e08..40c2603a 100644 --- a/tests/test_import_export.py +++ b/tests/test_import_export.py @@ -308,11 +308,13 @@ def test_import_export_event_details(app): ) output = get_output_of_command('export_site') - assert len(json.loads(output)['agendas']) == 2 + data = json.loads(output) + data['agendas'][0]['events'][0]['publication_datetime'] = '0001-01-01 00:00:00' + assert len(data['agendas']) == 2 import_site(data={}, clean=True) with tempfile.NamedTemporaryFile() as f: - f.write(force_bytes(output)) + f.write(force_bytes(json.dumps(data))) f.flush() call_command('import_site', f.name)
=> l'import se fait bien, mais ensuite:
output = get_output_of_command('export_site') data = json.loads(output) data['agendas'][0]['events'][0]['publication_datetime'] = '0001-01-01 00:00:00' assert len(data['agendas']) == 2 import_site(data={}, clean=True) with tempfile.NamedTemporaryFile() as f: f.write(force_bytes(json.dumps(data))) f.flush() call_command('import_site', f.name) assert Agenda.objects.count() == 2 assert Event.objects.count() == 2 > first_imported_event = Agenda.objects.get(label='Foo Bar').event_set.first() ... _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (100,), kwargs = {} def inner(*args, **kwargs): with self: > return func(*args, **kwargs) E ValueError: year -1 is out of range args = (100,) func = <built-in method fetchmany of psycopg2.extensions.cursor object at 0x7fd6cce9b5b0> kwargs = {} self = <django.db.utils.DatabaseErrorWrapper object at 0x7fd6cd655950> ../../envs/publik-env-py3/lib/python3.13/site-packages/django/db/utils.py:98: ValueError
On est probablement sur un import qui se fait sans erreur, mais qui plante ensuite en lecture
(Peut-être aussi lors de la génération du snapshot, puisqu'on ne trouve pas de trace d'un import dans l'historique de l'agenda)
Updated by Lauréline Guérin 3 days ago
on peut aussi, dans l'UI, sur la page de modification d'un event, mettre une date de publication (ou la date de l'event), mettre 0001-01-01, c'est bien sauvé dans la DB, mais ensuite la moindre lecture lève une ValueError